pub fn read_feed<P: AsRef<Path>>(path: P) -> Result<Feed>Expand description
Read a protobuf feed from disk.
§Behavior
- Reads the entire file at
pathinto memory. - Decodes the bytes into a
Feedusingprost’sMessage::decode.
§Arguments
path: Path to the.pbfile to read.
§Returns
The decoded Feed on success.
§Errors
- I/O errors from
fs::read, wrapped with context"failed to read {path}". - Protobuf decode errors from
Feed::decode, wrapped with context"failed to decode protobuf: {path}". - The error type is
anyhow::Errorvia your crate-wideResult.
§Example
use std::path::PathBuf;
use linkleaf_core::fs::read_feed;
use anyhow::Result;
fn main() -> Result<()> {
let path = PathBuf::from("mylinks.pb");
let feed = read_feed(&path)?;
println!("title: {}, links: {}", feed.title, feed.links.len());
Ok::<(), anyhow::Error>(())
}