parse_file

Function parse_file 

Source
pub fn parse_file<T: Descriptor>(content: &[u8]) -> Result<T, Error>
Expand description

Parses a descriptor from file content with automatic decompression.

This function handles the common case of reading a descriptor from a file:

  1. Automatically decompresses the content if compressed
  2. Strips any @type annotation from the beginning
  3. Parses the descriptor using the type’s parse method

§Type Parameters

  • T - The descriptor type to parse (must implement Descriptor)

§Arguments

  • content - The raw file content (possibly compressed)

§Returns

The parsed descriptor.

§Errors

Returns Error::Parse if:

  • Decompression fails
  • The content is not valid UTF-8
  • The descriptor content is malformed

§Example

use stem_rs::descriptor::{parse_file, ServerDescriptor};

let content = std::fs::read("cached-descriptors").unwrap();
let descriptor: ServerDescriptor = parse_file(&content).unwrap();
println!("Parsed descriptor for: {}", descriptor.nickname);

§See Also