Expand description
§use-set
Small mathematical set helpers for `RustUse`.
Explicit membership, subset, disjointness, and order-preserving set operations over slices.
§Install
[dependencies]
use-set = "0.0.1"§Foundation
use-set provides a deliberately small set-theoretic surface over ordinary slices. It treats duplicates as membership noise, exposes direct predicates such as contains_member, is_subset, and are_disjoint, and returns unique Vec<T> values for set operations while preserving first-seen order. The API stays explicit and dependency-free instead of introducing a wrapper collection type.
Membership and relationscontains_member, is_subset, and are_disjoint make set intent explicit at the call site.
|
Order-preserving operationsset_union, set_intersection, and set_difference return unique results without losing the order of first appearance.
|
Symmetric differenceset_symmetric_difference covers the common "in exactly one side" case directly.
|
| Helper group | Primary items | Best fit |
|---|---|---|
| Membership and relations | contains_member, is_subset, are_disjoint | Call sites that want readable set checks over existing slices |
| Set operations | set_union, set_intersection, set_difference | Small apps and utilities that need explicit, unique results without introducing a custom set type |
| Exclusive-membership helpers | set_symmetric_difference | Comparing two slices for values that appear on exactly one side |
§When to use directly
Choose use-set directly when mathematical set helpers are the only surface you need and you want to keep that concern narrower than the umbrella facade.
| Scenario | Use use-set directly? | Why |
|---|---|---|
| You already have slices and want explicit set predicates | Yes | The API avoids extra collection wrappers and keeps intent obvious |
| You need unique set-operation results but still care about input order | Yes | The operation helpers preserve first-seen order while removing duplicates |
| You also need geometry, probability, or other math domains | Usually no | use-math can compose the concrete surfaces behind features |
§Scope
- The current surface is intentionally small and concrete.
- Helpers work over ordinary slices and cloned output vectors instead of a custom set type.
- Boolean logic and general-purpose collection utilities belong in adjacent or external crates.
§Examples
§Membership and relations
use use_set::{are_disjoint, contains_member, is_subset};
let left = [1, 2, 2, 3];
let right = [2, 3, 4];
assert!(contains_member(&left, &2));
assert!(is_subset(&[2, 3], &right));
assert!(!are_disjoint(&left, &right));§Order-preserving set operations
use use_set::{set_difference, set_intersection, set_symmetric_difference, set_union};
let left = [1, 2, 2, 3];
let right = [3, 4, 2, 5];
assert_eq!(set_union(&left, &right), vec![1, 2, 3, 4, 5]);
assert_eq!(set_intersection(&left, &right), vec![2, 3]);
assert_eq!(set_difference(&left, &right), vec![1]);
assert_eq!(set_symmetric_difference(&left, &right), vec![1, 4, 5]);§Status
use-set is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent collection and algebra crates continue to grow around it.
Set utilities for RustUse.
Modules§
- prelude
- Common ergonomic imports for
use-set.
Functions§
- are_
disjoint - Returns whether
leftandrightshare no common members. - contains_
member - Returns whether
valueis a member ofset. - is_
subset - Returns whether every unique value in
leftappears inright. - set_
difference - Returns the unique members of
left \ rightin the order they first appear inleft. - set_
intersection - Returns the unique members of
left ∩ rightin the order they first appear inleft. - set_
symmetric_ difference - Returns the unique members that appear in exactly one of
leftorright. - set_
union - Returns the unique members of
left ∪ rightin first-seen order.