std-method
HashSet::take
Remove the stored element and transfer its ownership to the caller. A missing query returns None. Expected stdout (not executed): Some("ready") true Common mistake: Confusing take with get, which leaves the element in the set.
Formal Syntax & Structure
rust syntaxrust
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T> where T: Borrow<Q>, Q: Hash + EqWorking Example
Example Snippetrust
fn main() { use std::collections::HashSet; let mut s = HashSet::from([String::from("ready")]); let item = s.take("ready"); println!("{:?} {}", item, s.is_empty());}