Trait fav_core::local::ProtoLocal

source ·
pub trait ProtoLocal: PathInfo + MessageFull {
    // Provided methods
    fn write(self) -> FavCoreResult<()> { ... }
    fn read() -> FavCoreResult<Self> { ... }
    fn remove() { ... }
}
Expand description

Protobuf local/persist utils for reading and writing

§Example

use fav_core::local::{ProtoLocal, PathInfo};

// Require `Msg` to implemente `protobuf::MessageFull`
impl PathInfo for Msg {
    const PATH: &'static str = "temp/msg";
}
// trait `ProtoLocal` will be auto implemented for `T: PathInfo + MessageFull`
let msg = Msg::default();
msg.clone().write();   // The Msg will be write to `.fav/msg`
let msg_read: Msg = Msg::read().unwrap();
assert_eq!(msg, msg_read);
Msg::remove();

Provided Methods§

source

fn write(self) -> FavCoreResult<()>

Write the protobuf to file, which is at PathInfo::PATH Create the parent directory if not exists

source

fn read() -> FavCoreResult<Self>

Read the protobuf from file, which is at PathInfo::PATH

source

fn remove()

Remove the resource, which is at PathInfo::PATH

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> ProtoLocal for T
where T: PathInfo + MessageFull,