pub trait MetadataFile<T>where
T: FileFormatSchema,{
type Err;
// Required methods
fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<T>,
) -> Result<Self, Self::Err>
where Self: Sized;
fn from_reader_with_schema(
reader: impl Read,
schema: Option<T>,
) -> Result<Self, Self::Err>
where Self: Sized;
fn from_str_with_schema(
s: &str,
schema: Option<T>,
) -> Result<Self, Self::Err>
where Self: Sized;
// Provided methods
fn from_file(file: impl AsRef<Path>) -> Result<Self, Self::Err>
where Self: Sized { ... }
fn from_stdin() -> Result<Self, Self::Err>
where Self: Sized { ... }
fn from_stdin_with_schema(schema: Option<T>) -> Result<Self, Self::Err>
where Self: Sized { ... }
fn from_reader(reader: impl Read) -> Result<Self, Self::Err>
where Self: Sized { ... }
}
Expand description
A trait for metadata files.
Metadata files are expected to adhere to a FileFormatSchema
that is encoded in them
(purposefully or not).
This trait provides a set of functions to allow the easy creation of objects representing
metadata files from a diverse set of inputs.
Some functions allow the optional creation of the metadata file objects based a provided
FileFormatSchema
.
Required Associated Types§
Required Methods§
Sourcefn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<T>,
) -> Result<Self, Self::Err>where
Self: Sized,
fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<T>,
) -> Result<Self, Self::Err>where
Self: Sized,
Creates Self
from file
, optionally validated by a schema
.
If a FileFormatSchema
is provided, Self
must be validated using it.
Sourcefn from_reader_with_schema(
reader: impl Read,
schema: Option<T>,
) -> Result<Self, Self::Err>where
Self: Sized,
fn from_reader_with_schema(
reader: impl Read,
schema: Option<T>,
) -> Result<Self, Self::Err>where
Self: Sized,
Creates Self
from a Read
implementer, optionally validated by a schema
.
If a FileFormatSchema
is provided, Self
must be validated using it.
Sourcefn from_str_with_schema(s: &str, schema: Option<T>) -> Result<Self, Self::Err>where
Self: Sized,
fn from_str_with_schema(s: &str, schema: Option<T>) -> Result<Self, Self::Err>where
Self: Sized,
Creates Self
from a string slice, optionally validated by a schema
.
If a FileFormatSchema
is provided, Self
must be validated using it.
§Note
When also implementing FromStr
, it is advisable to redirect its implementation to call
Self::from_str_with_schema
with None
as schema
.
Provided Methods§
Sourcefn from_file(file: impl AsRef<Path>) -> Result<Self, Self::Err>where
Self: Sized,
fn from_file(file: impl AsRef<Path>) -> Result<Self, Self::Err>where
Self: Sized,
Creates Self
from file.
§Note
Implementations of this function are expected to automatically detect a FileFormatSchema
that the resulting Self
is based on.
The blanket implementation calls Self::from_file_with_schema
with None
as schema
.
Sourcefn from_stdin() -> Result<Self, Self::Err>where
Self: Sized,
fn from_stdin() -> Result<Self, Self::Err>where
Self: Sized,
§Note
Implementations of this function are expected to automatically detect a FileFormatSchema
that the resulting Self
is based on.
The blanket implementation calls Self::from_stdin_with_schema
with None
as schema
.
Sourcefn from_stdin_with_schema(schema: Option<T>) -> Result<Self, Self::Err>where
Self: Sized,
fn from_stdin_with_schema(schema: Option<T>) -> Result<Self, Self::Err>where
Self: Sized,
Creates Self
from stdin
, optionally validated by a schema
.
If a FileFormatSchema
is provided, Self
must be validated using it.
The blanket implementation calls Self::from_reader_with_schema
by passing in stdin
and the provided schema
.
Sourcefn from_reader(reader: impl Read) -> Result<Self, Self::Err>where
Self: Sized,
fn from_reader(reader: impl Read) -> Result<Self, Self::Err>where
Self: Sized,
Creates Self
from a Read
implementer.
§Note
Implementations of this function are expected to automatically detect a FileFormatSchema
that the resulting Self
is based on.
The blanket implementation calls Self::from_reader_with_schema
with None
as
schema
.