Skip to main content

Crate type_sets

Crate type_sets 

Source
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

See each trait’s documentation for details.

§Feature flags

  • assertions: enables the assert module.

§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 Contains it, and addresses can be converted into dynamic addresses for any Subset of 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§

AsTypeSet
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.

Type Aliases§

Insert
Type alias for adding a new member to a type set.
Union
Type alias for the union of two type sets.