Skip to main content

Format

Trait Format 

Source
pub trait Format {
    // Required methods
    fn import<R: Read>(&self, reader: R) -> Result<Narrative>;
    fn export<W: Write>(&self, narrative: &Narrative, writer: W) -> Result<()>;

    // Provided methods
    fn import_str(&self, data: &str) -> Result<Narrative> { ... }
    fn export_str(&self, narrative: &Narrative) -> Result<String> { ... }
}
Expand description

Trait for formats that can import and export narratives.

This trait defines a common interface for reading and writing narratives in various formats (GeoJSON, CSV, etc.).

Required Methods§

Source

fn import<R: Read>(&self, reader: R) -> Result<Narrative>

Import a narrative from a reader.

§Errors

Returns an error if the data is malformed or doesn’t match the expected format.

Source

fn export<W: Write>(&self, narrative: &Narrative, writer: W) -> Result<()>

Export a narrative to a writer.

§Errors

Returns an error if the write operation fails.

Provided Methods§

Source

fn import_str(&self, data: &str) -> Result<Narrative>

Import a narrative from a string.

This is a convenience method that wraps the string in a reader.

Source

fn export_str(&self, narrative: &Narrative) -> Result<String>

Export a narrative to a string.

This is a convenience method that collects output into a String.

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§