pub struct Set { /* private fields */ }Expand description
One set, with its key held for you.
This is 15 section 2’s shape: the name is spelled where the handle is made
and nowhere else, so a typo is one compile error at one line instead of a
lookup that quietly misses at three call sites.
let db = yo::open(yo::MEMORY)?;
let online = db.set("online");
online.add("alice")?;
online.add("bob")?;
assert!(online.contains("alice")?);
assert_eq!(online.len()?, 2);
online.remove("alice")?;
assert!(!online.contains("alice")?);Implementations§
Source§impl Set
impl Set
Sourcepub fn members(&self) -> Result<Vec<Vec<u8>>>
pub fn members(&self) -> Result<Vec<Vec<u8>>>
Every member, owned. SMEMBERS.
An empty Vec for a key that is not there. Sets::members is the
version that tells the two apart, and this one does not because a handle
on a key that was never written to is the ordinary way to start.
§Errors
As Sets::add.
Sourcepub fn move_to(&self, to: &Set, member: impl AsRef<[u8]>) -> Result<bool>
pub fn move_to(&self, to: &Set, member: impl AsRef<[u8]>) -> Result<bool>
Move one member into another set, and say whether it moved. SMOVE.
§Errors
As Sets::add, and Code::Invalid when to belongs to a different
database.
Sourcepub fn intersect(&self, others: &[&Set]) -> Result<Vec<Vec<u8>>>
pub fn intersect(&self, others: &[&Set]) -> Result<Vec<Vec<u8>>>
Everything in this set and in all of others. SINTER.
let db = yo::open(yo::MEMORY)?;
let a = db.set("a");
let b = db.set("b");
a.add_many(&["x", "y"])?;
b.add_many(&["y", "z"])?;
assert_eq!(a.intersect(&[&b])?, vec![b"y".to_vec()]);§Errors
As Set::move_to.
Sourcepub fn intersect_len(&self, others: &[&Set], limit: usize) -> Result<usize>
pub fn intersect_len(&self, others: &[&Set], limit: usize) -> Result<usize>
How many members this set shares with all of others. SINTERCARD.
A limit of zero means no limit.
§Errors
As Set::move_to.
Sourcepub fn union_len(&self, others: &[&Set], limit: usize) -> Result<usize>
pub fn union_len(&self, others: &[&Set], limit: usize) -> Result<usize>
How many members this set and others have between them. SUNIONCARD.
A limit of zero means no limit.
§Errors
As Set::move_to.
Sourcepub fn difference_len(&self, others: &[&Set], limit: usize) -> Result<usize>
pub fn difference_len(&self, others: &[&Set], limit: usize) -> Result<usize>
How many members this set has that no set in others has. SDIFFCARD.
A limit of zero means no limit.
§Errors
As Set::move_to.