[][src]Struct no_proto::buffer::NP_Buffer

pub struct NP_Buffer {
    pub memory: Rc<NP_Memory>,
    // some fields omitted
}

Fields

memory: Rc<NP_Memory>

Implementations

impl NP_Buffer[src]

Buffers contain the memory of each object and allow you to access and mutate data.

pub fn new(model: Rc<NP_Schema>, memory: Rc<NP_Memory>) -> Self[src]

Generate a complete new, empty buffer

pub fn root<T: NP_Value + Default>(&mut self) -> Result<NP_Ptr<T>, NP_Error>[src]

Get the root pointer of the buffer. You should make sure the type in the argument matches the schema.

pub fn deep_set<X: NP_Value + Default>(
    &mut self,
    path: &str,
    value: X
) -> Result<(), NP_Error>
[src]

Used to set scalar values inside the buffer, the path only works with dot notation. This does not work with collection types or NP_JSON.

The type that you cast the request to will be compared to the schema, if it doesn't match the schema the request will fail.

pub fn deep_clear(&self, path: &str) -> Result<(), NP_Error>[src]

Clear an inner value from the buffer. The path only works with dot notation. This can also be used to clear deeply nested collection objects.

pub fn deep_get<X: NP_Value + Default>(
    &self,
    path: &str
) -> Result<Option<Box<X>>, NP_Error>
[src]

Retrieve an inner value from the buffer. The path only works with dot notation. You can also use this to get JSON by casting the request type to NP_JSON. This can also be used to retrieve deeply nested collection objects.

The type that you cast the request to will be compared to the schema, if it doesn't match the schema the request will fail.

pub fn maybe_compact<F>(
    self,
    new_capacity: Option<u32>,
    callback: F
) -> Result<NP_Buffer, NP_Error> where
    F: FnMut(NP_Compact_Data) -> bool, 
[src]

This performs a compaction if the closure provided as the second argument returns true, otherwise it just returns the original buffer. The closure is provided an argument that contains the original size of the buffer, how many bytes could be saved by compaction, and how large the new buffer would be after compaction.

pub fn compact(self, new_capacity: Option<u32>) -> Result<NP_Buffer, NP_Error>[src]

Compacts a buffer to remove an unused bytes or free space after a mutation. This is a pretty expensive operation so should be done sparingly.

pub fn calc_wasted_bytes(&self) -> Result<u32, NP_Error>[src]

Recursively measures how many bytes each element in the buffer is using and subtracts that from the size of the buffer. This will let you know how many bytes can be saved from a compaction.

Auto Trait Implementations

impl !Send for NP_Buffer

impl !Sync for NP_Buffer

impl Unpin for NP_Buffer

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.