pub struct Vec<T, DS>where
DS: DataStore,{ /* private fields */ }Expand description
mimics the API of Vec
Implementations§
Source§impl<'a, T, DS> Vec<T, DS>
impl<'a, T, DS> Vec<T, DS>
Sourcepub fn extend<I, Q>(
&mut self,
iter: I,
) -> Result<(), ExtendError<I::Item, I::IntoIter, Error<DS::DbError>>>
pub fn extend<I, Q>( &mut self, iter: I, ) -> Result<(), ExtendError<I::Item, I::IntoIter, Error<DS::DbError>>>
Extends the list with the contents of an iterator.
The iterator item may be any borrowed form of the lists item type, as long as the serialized form matches between borrowed and not borrowed.
§Errors
This can fail if the underlying database ran into a problem or if serialization failed.
§Examples
#[dbstruct::dbstruct(db=btreemap)]
struct Test {
list: Vec<String>,
}
let db = Test::new()?;
db.list().extend(["one", "two", "three"])?;
assert_eq!(db.list().get(0)?, Some("one".to_owned()));
assert_eq!(db.list().get(2)?, Some("three".to_owned()));Source§impl<'a, T, E, DS> Vec<T, DS>
This can be quite slow as it gets each element from
the db individually. Consider using the Default wrapper
instead of this if the VecDeque is “small” enough.
impl<'a, T, E, DS> Vec<T, DS>
This can be quite slow as it gets each element from
the db individually. Consider using the Default wrapper
instead of this if the VecDeque is “small” enough.
Source§impl<T, E, DS> Vec<T, DS>
impl<T, E, DS> Vec<T, DS>
Sourcepub fn get(&self, index: usize) -> Result<Option<T>, Error<E>>
pub fn get(&self, index: usize) -> Result<Option<T>, Error<E>>
Returns the element at index if there is one.
§Errors
This can fail if the underlying database ran into a problem or if serialization failed.
§Examples
#[dbstruct::dbstruct(db=btreemap)]
struct Test {
list: Vec<String>,
}
let db = Test::new()?;
assert_eq!(db.list().get(0)?, None);
db.list().push("a")?;
db.list().push("b")?;
assert_eq!(db.list().get(0)?, Some("a".to_owned()));Sourcepub fn push<Q>(&self, value: &Q) -> Result<(), Error<E>>
pub fn push<Q>(&self, value: &Q) -> Result<(), Error<E>>
Appends an element to the back of the collection.
The item may be any borrowed form of the lists item type, but the serialized form must match the not borrowed serialized form.
§Errors
This can fail if the underlying database ran into a problem or if serialization failed.
§Examples
#[dbstruct::dbstruct(db=btreemap)]
struct Test {
list: Vec<String>,
}
let db = Test::new()?;
db.list().push("a")?;
db.list().push("b")?;Sourcepub fn pop(&self) -> Result<Option<T>, Error<E>>
pub fn pop(&self) -> Result<Option<T>, Error<E>>
Removes the last element from this database vector and returns it,
or None if it is empty
§Errors
This can fail if the underlying database ran into a problem or if serialization failed.
§Examples
#[dbstruct::dbstruct(db=btreemap)]
struct Test {
list: Vec<String>,
}
let db = Test::new()?;
db.list().extend(["a", "b", "c"])?;
assert_eq!(db.list().pop()?, Some("c".to_owned()));Sourcepub fn clear(&self) -> Result<(), Error<E>>
pub fn clear(&self) -> Result<(), Error<E>>
Clears the list, removing all values.
§Errors
This can fail if the underlying database ran into a problem or if serialization failed.
§Examples
#[dbstruct::dbstruct(db=btreemap)]
struct Test {
list: Vec<String>,
}
let db = Test::new()?;
db.list().extend(["a", "b", "c"])?;
assert!(!db.list().is_empty());
db.list().clear();
assert!(db.list().is_empty());Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the list, also referred to as its ‘length’.
§Examples
#[dbstruct::dbstruct(db=btreemap)]
struct Test {
list: Vec<String>,
}
let db = Test::new()?;
db.list().extend(["a", "b", "c"])?;
assert_eq!(db.list().len(), 3);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the list has a length of 0.
§Examples
#[dbstruct::dbstruct(db=btreemap)]
struct Test {
list_a: Vec<String>,
list_b: Vec<String>,
}
let db = Test::new()?;
db.list_a().extend(["a", "b", "c"])?;
assert!(!db.list_a().is_empty());
assert!(db.list_b().is_empty());Trait Implementations§
Source§impl<'a, T, E, DS> IntoIterator for &'a Vec<T, DS>
This can be quite slow as it gets each element from
the db individually. Consider using the Default wrapper
instead of this if the Vec is “small” enough.
impl<'a, T, E, DS> IntoIterator for &'a Vec<T, DS>
This can be quite slow as it gets each element from
the db individually. Consider using the Default wrapper
instead of this if the Vec is “small” enough.