type-sets
Compile-time set operations on Rust tuples.
type-sets treats tuples as sets of types. You can check whether a set contains a type, compare two sets, and build new sets, all in the type system with no runtime cost. The order of the types doesn't matter, so (A, B) and (B, A) are the same set. Sets can have up to 24 members.
Operations
Contains<E>: the set contains the typeE.Subset<S>: every member of the set is also inS.Superset<S>: the set contains every member ofS.SetEqual<R>: the two sets have the same members, in any order.IsEmpty: the set has no members.Insert<T, E>: the setTwithEadded.Union<T, R>: all members ofTandR.Members: the members of a set asTypeIds, available at runtime.
Most of these are traits that you use as bounds:
use Contains;
/// Only accepts messages that are in the set `S`.
Assertions
With the assertions feature, the assert module provides functions that check set relations at compile time. They are handy in tests:
[]
= { = "0.2", = ["assertions"] }
use *;
;
;
;
;
;
Read the documentation for more details.
Libraries using type-sets
- zestors: an actor framework with Erlang/OTP-style supervision. An actor's interface is a set of message types. Sending a message checks that the interface
Containsit, and addresses can be converted into dynamic addresses for anySubsetof the interface. - axum-error-sets: typed, composable HTTP error sets for axum. Each handler declares the set of status codes it can return, and smaller sets convert into any
Superset.
License
Licensed under either of MIT or Apache-2.0, at your option.