std-method
HashSet::get
Return a shared reference to the stored element equal to the query. Unlike contains, get provides the actual stored representation. Expected stdout (not executed): Some("rust") Common mistake: Expecting an owned element or a mutable reference from get.
Formal Syntax & Structure
rust syntaxrust
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T> where T: Borrow<Q>, Q: Hash + EqWorking Example
Example Snippetrust
fn main() { use std::collections::HashSet; let s = HashSet::from([String::from("rust")]); println!("{:?}", s.get("rust"));}