read_feed

Function read_feed 

Source
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 path into memory.
  • Decodes the bytes into a Feed using prost’s Message::decode.

§Arguments

  • path: Path to the .pb file 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::Error via your crate-wide Result.

§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>(())
}