Writer

Struct Writer 

Source
pub struct Writer { /* private fields */ }
Expand description

Writer for loam files

The writer can be used to create or append to an existing file.

Implementations§

Source§

impl Writer

Source

pub fn new<P>(path: P) -> Result<Self>
where P: AsRef<Path>,

Create a new Writer

Examples found in repository?
examples/write.rs (line 7)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let mut root = node::Node::new("Root");
5    root.push(20);
6    root.push(40);
7    let mut w = loam::Writer::new("test.loam")?;
8    let id = w.push(&root)?;
9    w.checkpoint(id)?;
10    Ok(())
11}
Source

pub fn push<D>(&mut self, data: &D) -> Result<Id>
where D: Serialize,

Push a chunk of data to the end of the file.

§Returns

Id chunk identifier

Examples found in repository?
examples/write.rs (line 8)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let mut root = node::Node::new("Root");
5    root.push(20);
6    root.push(40);
7    let mut w = loam::Writer::new("test.loam")?;
8    let id = w.push(&root)?;
9    w.checkpoint(id)?;
10    Ok(())
11}
Source

pub fn checkpoint(&mut self, id: Id) -> Result<()>

Add a checkpoint to the file. The Id commonly points to the root of a tree of nodes.

In order to be read back, a file must end with a checkpoint.

Examples found in repository?
examples/write.rs (line 9)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let mut root = node::Node::new("Root");
5    root.push(20);
6    root.push(40);
7    let mut w = loam::Writer::new("test.loam")?;
8    let id = w.push(&root)?;
9    w.checkpoint(id)?;
10    Ok(())
11}

Auto Trait Implementations§

§

impl Freeze for Writer

§

impl RefUnwindSafe for Writer

§

impl Send for Writer

§

impl Sync for Writer

§

impl Unpin for Writer

§

impl UnwindSafe for Writer

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, 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, 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.