Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder {
    // Required method
    fn get_entity(&self, name: &str) -> Option<&str>;

    // Provided methods
    fn decode_entity(&self, name: &str) -> Result<DecodedEntity<'_>> { ... }
    fn decode_string<'a>(&self, s: &'a str) -> Result<Cow<'a, str>> { ... }
}
Expand description

Trait for decoding entities to values.

Required Methods§

Source

fn get_entity(&self, name: &str) -> Option<&str>

Retrieves the definition for an entity by name.

Provided Methods§

Source

fn decode_entity(&self, name: &str) -> Result<DecodedEntity<'_>>

Decodes an entity by either parsing a numeric entity (e.g. "&#32") or calling get_entity.

Source

fn decode_string<'a>(&self, s: &'a str) -> Result<Cow<'a, str>>

Decodes an entire string, replacing all entities inside it with their values resolved by decode_entity. If the string does not contain any entities, it is returned unchanged as a borrowed string slice. Otherwise, an owned string containing the replacements is returned.

Implementations on Foreign Types§

Source§

impl Decoder for ()

Fallback Decoder that only looks up global entities (with Entity::global).

Source§

fn get_entity(&self, name: &str) -> Option<&str>

Source§

impl<D: Decoder> Decoder for &D

Source§

fn get_entity(&self, name: &str) -> Option<&str>

Source§

fn decode_entity(&self, entity: &str) -> Result<DecodedEntity<'_>>

Implementors§