std-method

HashSet::is_disjoint

Return true if the sets share no equal elements. This tests overlap without materializing the intersection. Expected stdout (not executed): true false Common mistake: Assuming disjoint means the sets have different sizes.

Formal Syntax & Structure

rust syntaxrust
pub fn is_disjoint(&self, other: &HashSet<T, S>) -> bool

Working Example

Example Snippetrust
fn main() {    use std::collections::HashSet;    let a = HashSet::from([1, 2]);    let b = HashSet::from([3, 4]);    let c = HashSet::from([2, 5]);    println!("{} {}", a.is_disjoint(&b), a.is_disjoint(&c));}
Rust Reference