Struct Vec

Source
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>

Source

pub fn extend<I, Q>( &mut self, iter: I, ) -> Result<(), ExtendError<I::Item, I::IntoIter, Error<DS::DbError>>>
where I: IntoIterator<Item = &'a Q>, T: Borrow<Q>, Q: Serialize + ?Sized,

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>
where E: Debug, T: Serialize + DeserializeOwned, DS: DataStore<DbError = E>,

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

pub fn iter(&self) -> Iter<'_, T, E, DS>

Source§

impl<T, E, DS> Vec<T, DS>
where E: Debug, T: Serialize + DeserializeOwned, DS: DataStore<DbError = E>,

Source

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()));
Source

pub fn push<Q>(&self, value: &Q) -> Result<(), Error<E>>
where T: Borrow<Q>, Q: Serialize + ?Sized,

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")?;
Source

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()));
Source

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());
Source

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);
Source

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<T, E, DS> Debug for Vec<T, DS>
where E: Debug, T: Serialize + DeserializeOwned + Debug, DS: DataStore<DbError = E>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T, E, DS> IntoIterator for &'a Vec<T, DS>
where E: Debug, T: Serialize + DeserializeOwned, DS: DataStore<DbError = E>,

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.

Source§

type IntoIter = Iter<'a, T, E, DS>

Which kind of iterator are we turning this into?
Source§

type Item = Result<T, Error<E>>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, DS> Freeze for Vec<T, DS>
where DS: Freeze,

§

impl<T, DS> !RefUnwindSafe for Vec<T, DS>

§

impl<T, DS> Send for Vec<T, DS>
where DS: Send, T: Send,

§

impl<T, DS> !Sync for Vec<T, DS>

§

impl<T, DS> Unpin for Vec<T, DS>
where DS: Unpin, T: Unpin,

§

impl<T, DS> UnwindSafe for Vec<T, DS>
where DS: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more