Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Rust B-Tree map for pub/sub services

License

NotificationsYou must be signed in to change notification settings

alttch/submap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

B-tree map for pub/sub services.

Subscription map

Usage

use submap::SubMap;typeClient =String;letmut smap:SubMap<Client> =SubMap::new();

where "Client" is a pub/sub client type, which is usually either a channel or astructure which contains a channel or locked socket or anything else, requiredto work with the client.

The client type MUST provide traits Ord, Eq and Clone.

All clients must be registered in the map, before they cansubscribe/unsubscribe. Use "register_client" function for this.

When "unregister_client" is called, it also automatically unsubscribes theclient from all the subscribed topics.

Separators and wildcards

[SubMap] supports the following masks:

  • this/is/a/topic - single topic subscription
  • this/?/a/topic - all topics which match the pattern (2nd chunk - any value)
  • this/is/* - all subtopics of "this/is"
  • * - all topics

Service symbols can be changed. E.g. let us create a subscription map withMQTT-style wildcards (+ for ? and # for *) but with the dot as the subtopicseparator:

use submap::SubMap;typeClient =String;letmut smap:SubMap<Client> =SubMap::new().separator('.').match_any("+").wildcard("#");

Note that "/topic/x", "topic/x" and "topic//x" are 3 different topics. Ifany kind of normalization is required, it should be done manually, beforecalling [SubMap] functions.

Formulas

[SubMap] supports formulas, which are used both to subscribe to a topic byformula or to get a list of clients which match one.

Formulas are non-standard pub/sub functionality and are useful when a clientwant to subscribe to topics which have got e.g. some importance level. Insteadof subscribing to all level topics, a client can subscribe to one topic with aformula:

use submap::SubMap;typeClient =String;letmut smap:SubMap<Client> =SubMap::new().separator('/').match_any("+").wildcard("#").formula_prefix("!");let client1 ="client1".to_owned();smap.register_client(&client1);smap.subscribe("some/!ge(2)/topic",&client1);assert_eq!(smap.get_subscribers("some/1/topic").len(),0);assert_eq!(smap.get_subscribers("some/2/topic").len(),1);assert_eq!(smap.get_subscribers("some/3/topic").len(),1);

See more: [mkmf::Formula].

Regular expressions

[SubMap] supports regular expressions in subtopic names.

Regular expressions are non-standard pub/sub functionality, are pretty slow(especially for subscribe/unsubscribe operations) and should be used withcaution. A regular expression can not contain the separator symbol.

use submap::SubMap;typeClient =String;letmut smap:SubMap<Client> =SubMap::new().separator('/').match_any("+").wildcard("#").regex_prefix("~");let client1 ="client1".to_owned();smap.register_client(&client1);smap.subscribe("some/~subtopic[0-9]+/topic",&client1);assert_eq!(smap.get_subscribers("some/subtopic1/topic").len(),1);assert_eq!(smap.get_subscribers("some/subtopic2/topic").len(),1);assert_eq!(smap.get_subscribers("some/subtopic333/topic").len(),1);assert_eq!(smap.get_subscribers("some/subtopicx/topic").len(),0);

Broadcast map

use submap::BroadcastMap;typeClient =String;letmut bmap:BroadcastMap<Client> =BroadcastMap::new();

Does the opposite job - clients are registered with regular names, while"get_clients_by_mask" function returns clients, which match the mask.

Note: the default separator is dot.

ACL map

letmut acl_map = submap::AclMap::new();

SubMap-based high-speed access control lists checker. Uses SubMap algorithmwith a single unit "client" to verify various access control lists.

Crate features

  • indexmap switches the engine toindexmap (the default is based onstd::collections::BTreeMap/BTreeSet), requires Hash trait implemented for mapclients.

The current engine can be obtained from

use submap::types::ENGINE;dbg!(ENGINE);// std-btree or indexmap

MSRV

1.81.0

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp