pub trait Info: Clone + Debug {
type Error: Error;
// Required methods
fn to_string(&self, pretty: bool) -> Result<String, InfoError<Self::Error>>;
fn to_writer(
&self,
writer: impl Write,
pretty: bool,
) -> Result<(), InfoError<Self::Error>>;
fn from_string(raw: impl AsRef<str>) -> Result<Self, InfoError<Self::Error>>;
fn from_reader(reader: impl Read) -> Result<Self, InfoError<Self::Error>>;
// Provided methods
fn to_path(
&self,
path: impl AsRef<Path>,
) -> Result<(), InfoError<Self::Error>> { ... }
fn from_path(path: impl AsRef<Path>) -> Result<Self, InfoError<Self::Error>> { ... }
fn from_path_async<'async_trait>(
path: impl 'async_trait + Send + AsRef<Path>,
) -> Pin<Box<dyn Future<Output = Result<Self, InfoError<Self::Error>>> + Send + 'async_trait>>
where Self: Send + 'async_trait { ... }
}
Expand description
Defines a serializable struct that we typically use for structs that are directly read and written to disk.
Required Associated Types§
Required Methods§
sourcefn to_writer(
&self,
writer: impl Write,
pretty: bool,
) -> Result<(), InfoError<Self::Error>>
fn to_writer( &self, writer: impl Write, pretty: bool, ) -> Result<(), InfoError<Self::Error>>
Serializes this Config to a reader.
§Arguments
writer
: TheWrite
r to write the serialized representation to.pretty
: If true, then it will be serialized using a pretty version of the backend (if available).
§Errors
This function may error if the serialization failed or if we failed to write to the given writer.
sourcefn from_reader(reader: impl Read) -> Result<Self, InfoError<Self::Error>>
fn from_reader(reader: impl Read) -> Result<Self, InfoError<Self::Error>>
Deserializes the contents of the given reader to an instance of ourselves.
§Arguments
reader
: TheRead
er who’s contents to deserialize.
§Returns
A new instance of Self
with its contents read from the given reader.
§Errors
This function may fail if we failed to read from the reader or if its contents were invalid for this object.
Provided Methods§
sourcefn to_path(&self, path: impl AsRef<Path>) -> Result<(), InfoError<Self::Error>>
fn to_path(&self, path: impl AsRef<Path>) -> Result<(), InfoError<Self::Error>>
Serializes this Config to a file at the given path.
This will always choose a pretty representation of the serialization (if applicable).
§Arguments
path
: The path where to write the file to.
§Errors
This function may error if the serialization failed or if we failed to create and/or write to the file.
sourcefn from_path_async<'async_trait>(
path: impl 'async_trait + Send + AsRef<Path>,
) -> Pin<Box<dyn Future<Output = Result<Self, InfoError<Self::Error>>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
fn from_path_async<'async_trait>(
path: impl 'async_trait + Send + AsRef<Path>,
) -> Pin<Box<dyn Future<Output = Result<Self, InfoError<Self::Error>>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
Deserializes this Config from the file at the given path, with the reading part done asynchronously.
Note that the parsing path cannot be done asynchronously. Also, note that, because serde does not support asynchronous deserialization, we have to read the entire file in one go.
§Arguments
path
: The path where to read the file from.
§Errors
This function may fail if we failed to open/read from the file or if its contents were invalid for this object.