Skip to main content

Crate use_set

Crate use_set 

Source
Expand description

§use-set

Small mathematical set helpers for `RustUse`.
Explicit membership, subset, disjointness, and order-preserving set operations over slices.

Rust 1.95.0+ Edition 2024 Set helpers License MIT or Apache-2.0

§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 relations
contains_member, is_subset, and are_disjoint make set intent explicit at the call site.
Order-preserving operations
set_union, set_intersection, and set_difference return unique results without losing the order of first appearance.
Symmetric difference
set_symmetric_difference covers the common "in exactly one side" case directly.
Helper groupPrimary itemsBest fit
Membership and relationscontains_member, is_subset, are_disjointCall sites that want readable set checks over existing slices
Set operationsset_union, set_intersection, set_differenceSmall apps and utilities that need explicit, unique results without introducing a custom set type
Exclusive-membership helpersset_symmetric_differenceComparing 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.

ScenarioUse use-set directly?Why
You already have slices and want explicit set predicatesYesThe API avoids extra collection wrappers and keeps intent obvious
You need unique set-operation results but still care about input orderYesThe operation helpers preserve first-seen order while removing duplicates
You also need geometry, probability, or other math domainsUsually nouse-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 left and right share no common members.
contains_member
Returns whether value is a member of set.
is_subset
Returns whether every unique value in left appears in right.
set_difference
Returns the unique members of left \ right in the order they first appear in left.
set_intersection
Returns the unique members of left ∩ right in the order they first appear in left.
set_symmetric_difference
Returns the unique members that appear in exactly one of left or right.
set_union
Returns the unique members of left ∪ right in first-seen order.