[][src]Struct storaget::VecPack

pub struct VecPack<T> where
    T: VecPackMember
{ /* fields omitted */ }

VecPack Small FS layer around a Vec<Pack> The naming could be confusing a bit, as VecPack is rather FSLayer<Vec<Pack>>, but maybe this could be too long and unnecessary. So VecPack behaves as a special Vec<Pack>.

Methods

impl<T> VecPack<T> where
    T: VecPackMember + Serialize + Deserialize<'de> + Default + Sized + Clone + TryFrom + From<<T as TryFrom>::TryFrom>, 
[src]

impl<T> VecPack<T> where
    T: VecPackMember + Deserialize<'de> + Default
[src]

pub fn new(path: PathBuf) -> PackResult<VecPack<T>>[src]

New VecPack Requires a PathBuf and returns an empty VecPack

pub fn load_or_init(path: PathBuf) -> PackResult<VecPack<T>>[src]

Load or init VecPack by a given Path If path does not exist, then we create it, then loads all the files, and tries to deserialize them. If a file cannot be read, or cannot be deserialized then we panic!

pub fn insert(&mut self, item: T) -> PackResult<()>[src]

Insert a new T to VecPack Only if ID is not taken

pub fn insert_pack(&mut self, item: Pack<T>) -> PackResult<()>[src]

Insert Pack to VecPack Only if ID is not taken

pub fn find_id(&self, id: &str) -> PackResult<&Pack<T>>[src]

Find ID and returns &Pack as an unmutable reference

pub fn find_id_mut(&mut self, id: &str) -> PackResult<&mut Pack<T>>[src]

Find ID and returns &mut Pack as a mutable reference

pub fn check_id_available(&self, id: &str) -> bool[src]

Check ID is available If ID is taken, returns false, otherwise returns true

pub fn as_vec_mut(&mut self) -> &mut Vec<Pack<T>>[src]

Returns data as a mutable reference to Vec<Pack>

pub fn as_vec(&self) -> &Vec<Pack<T>>[src]

Returns data as unmutable reference to Vec<Pack>

pub fn get_path(&self) -> &Path[src]

Returns VecPack &Path

Methods from Deref<Target = Vec<Pack<T>>>

pub fn capacity(&self) -> usize1.0.0[src]

Returns the number of elements the vector can hold without reallocating.

Examples

let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);

pub fn as_slice(&self) -> &[T]1.7.0[src]

Extracts a slice containing the entire vector.

Equivalent to &s[..].

Examples

use std::io::{self, Write};
let buffer = vec![1, 2, 3, 5, 8];
io::sink().write(buffer.as_slice()).unwrap();

pub fn as_ptr(&self) -> *const T1.37.0[src]

Returns a raw pointer to the vector's buffer.

The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.

The caller must also ensure that the memory the pointer (non-transitively) points to is never written to (except inside an UnsafeCell) using this pointer or any pointer derived from it. If you need to mutate the contents of the slice, use as_mut_ptr.

Examples

let x = vec![1, 2, 4];
let x_ptr = x.as_ptr();

unsafe {
    for i in 0..x.len() {
        assert_eq!(*x_ptr.add(i), 1 << i);
    }
}

pub fn len(&self) -> usize1.0.0[src]

Returns the number of elements in the vector, also referred to as its 'length'.

Examples

let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);

pub fn is_empty(&self) -> bool1.0.0[src]

Returns true if the vector contains no elements.

Examples

let mut v = Vec::new();
assert!(v.is_empty());

v.push(1);
assert!(!v.is_empty());

Trait Implementations

impl<T> Deref for VecPack<T> where
    T: VecPackMember
[src]

type Target = Vec<Pack<T>>

The resulting type after dereferencing.

impl<'a, T> IntoIterator for &'a mut VecPack<T> where
    T: VecPackMember
[src]

type Item = &'a mut Pack<T>

The type of the elements being iterated over.

type IntoIter = VecPackIterMut<'a, T>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<T> RefUnwindSafe for VecPack<T> where
    T: RefUnwindSafe

impl<T> Send for VecPack<T> where
    T: Send

impl<T> Sync for VecPack<T> where
    T: Sync

impl<T> Unpin for VecPack<T> where
    T: Unpin

impl<T> UnwindSafe for VecPack<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.