Expand description
type-sets implements compile-time set operations on tuples.
A tuple of types is treated as a set: the order doesn’t matter, so (A, B) and (B, A)
are the same set. Sets can have up to 24 members. See AsTypeSet.
§Basic example
Most operations are traits that you use as bounds:
use type_sets::Contains;
/// Only accepts messages that are in the set `S`.
fn send<S: Contains<M>, M>(message: M) {
// ...
}With the assertions feature, the assert module checks set relations at
compile time:
assert::contains::<(i32, i16), i32>();
assert::subset::<(i32,), (i32, i64)>();
assert::superset::<(i32, i16), (i32,)>();
assert::eq::<(i32, i16), (i16, i32)>();§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.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.
See each trait’s documentation for details.
§Feature flags
assertions: enables theassertmodule.
§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.
Modules§
- assert
- Functions that check set relations at compile time. Each one compiles only if the relation holds, and does nothing at runtime.
Traits§
- AsType
Set - The main trait for representing a set of types.
- Contains
- Implemented for any set that contains a member
E. - Extend
- Trait for extending a type set with another type set.
- IsEmpty
- Indicates that a set is empty, i.e., it contains no members.
- Members
- Trait for retrieving the members of a type set as
TypeIds. - Push
- Trait for adding a new member to a type set.
- SetEqual
- Indicates that two sets are equal, i.e., they contain the same members.
- Subset
- Implemented for any set that is a subset of set
S. - Superset
- Implemented for any set that is a superset of set
S.