std-method

BTreeSet::split_off

Keep elements smaller than the boundary and return a second set containing all elements at or above it. The boundary need not exist in the original set. Expected stdout (not executed): [1, 4] [6, 9] Common mistake: Expecting the boundary element to remain in the original set.

Formal Syntax & Structure

rust syntaxrust
fn split_off<Q>(&mut self, value: &Q) -> BTreeSet<T> where T: Borrow<Q> + Ord, Q: Ord + ?Sized

Working Example

Example Snippetrust
fn main() {    use std::collections::BTreeSet;    let mut ids = BTreeSet::from([1, 4, 6, 9]);    let later = ids.split_off(&5);    println!("{:?}", ids.into_iter().collect::<Vec<_>>());    println!("{:?}", later.into_iter().collect::<Vec<_>>());}
Rust Reference