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:
- Automatically decompresses the content if compressed
- Strips any
@typeannotation from the beginning - Parses the descriptor using the type’s
parsemethod
§Type Parameters
T- The descriptor type to parse (must implementDescriptor)
§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
parse_file_with_annotation- Also returns the type annotation if presentDescriptor::parse- Parse from string without decompression