pub struct VoluntaryServitude<T> { /* private fields */ }
Expand description

Lock-free appendable list (also called VS)

Parallel examples in main lib docs

let list = vs![3, 2];
assert_eq!(list.len(), 2);
assert_eq!(list.iter().collect::<Vec<_>>(), vec![&3, &2]);

list.clear();
assert!(list.is_empty());

// You can deep copy a `VS` if T is Copy
use std::iter::FromIterator;
let list2 = VS::from_iter(list.iter());
list2.append(3);
assert_eq!(list.len() + 1, list2.len());

for el in list.iter() {
    assert_eq!(el, &3);
}

Implementations

Atomically extracts current size, be careful with data-races when using it

May grow or be set to 0

let list = vs![3, 2];
assert_eq!(list.len(), 2);
list.append(5);
assert_eq!(list.len(), 3);
list.clear();
assert_eq!(list.len(), 0);

Atomically checks if VS is empty, be careful with data-races when using it

let list = vs![];
assert!(list.is_empty());
list.append(());
assert!(!list.is_empty());

Makes lock-free iterator based on VoluntaryServitude

let list = vs![3, 2];
assert_eq!(list.iter().collect::<Vec<_>>(), vec![&3, &2]);

Clears list (iterators referencing old chain will still work)

let list = vs![3, 2];
let iter = list.iter();
list.clear();
assert_eq!(iter.len(), 2);
assert_eq!(list.len(), 0);

Insert element after last node

let list = vs![];
let mut iter = list.iter();
list.append(3);
assert!(iter.is_empty());
iter = list.iter();
list.append(8);
assert_eq!(iter.collect::<Vec<_>>(), vec![&3, &8]);

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Executes the destructor for this type. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.