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§
sourcefn write(self) -> FavCoreResult<()>
fn write(self) -> FavCoreResult<()>
Write the protobuf to file, which is at PathInfo::PATH
Create the parent directory if not exists
sourcefn read() -> FavCoreResult<Self>
fn read() -> FavCoreResult<Self>
Read the protobuf from file, which is at PathInfo::PATH
Object Safety§
This trait is not object safe.