ParseFrom

Trait ParseFrom 

Source
pub trait ParseFrom<Source>: Sized {
    // Required method
    fn parse_from(source: Source) -> Option<Self>;
}
Expand description

Generic trait for parsing types from various sources using GAT

This trait provides a unified interface for constructing types from different data sources (JSON values, XML elements, etc.) using Generic Associated Types (GAT) for flexible lifetime handling.

§Examples

use feedparser_rs::types::generics::ParseFrom;
use feedparser_rs::types::Person;
use serde_json::json;

let json = json!({"name": "John Doe", "url": "https://example.com"});
let person = Person::parse_from(&json);
assert!(person.is_some());
assert_eq!(person.unwrap().name.as_deref(), Some("John Doe"));

Required Methods§

Source

fn parse_from(source: Source) -> Option<Self>

Parse from the given source

§Arguments
  • source - The source data to parse from
§Returns
  • Some(Self) - Successfully parsed instance
  • None - Failed to parse (missing required fields, wrong type, etc.)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§