14 releases

0.2.7 Mar 8, 2024
0.2.5 Jun 17, 2023
0.2.3 Oct 6, 2022
0.1.8 May 30, 2022
0.1.2 Dec 26, 2021

#194 in Network programming

Download history 5/week @ 2023-12-03 5/week @ 2023-12-10 2/week @ 2023-12-24 16/week @ 2023-12-31 22/week @ 2024-01-21 6/week @ 2024-01-28 11/week @ 2024-02-04 5/week @ 2024-02-11 11/week @ 2024-02-18 46/week @ 2024-02-25 157/week @ 2024-03-03 39/week @ 2024-03-10 35/week @ 2024-03-17

278 downloads per month
Used in 7 crates (4 directly)

Apache-2.0

33KB
791 lines

submap

B-tree map for pub/sub services.

Subscription map

Usage

let mut smap: SubMap<Client> = SubMap::new();

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

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

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

When "unregister_client" is called, it also automatically unsubscribes the client 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 with MQTT-style wildcards (+ for ? and # for *) but with the dot as the subtopic separator:

let mut smap: SubMap<Client> =
    SubMap::new().separator('.').match_any("+").wildcard("#");

Note that "/topic/x", "topic/x" and "topic//x" are 3 different topics. If any kind of normalization is required, it should be done manually, before calling SubMap functions.

Broadcast map

let mut 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

let mut acl_map = AclMap::new();

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

Crate features

  • indexmap switches the engine to indexmap (the default is based on std::collections::BTreeMap/BTreeSet), requires Hash trait implemented for map clients.

The current engine can be obtained from

use submap::types::ENGINE;

dbg!(ENGINE); // std-btree or indexmap

Cargo crate

https://crates.io/crates/submap

Dependencies

~0–1.2MB
~26K SLoC