pub trait FromGff: Sized {
type Error;
const MAGIC: [u8; 4];
// Required method
fn from_gff(gff: &Gff) -> Result<Self, Self::Error>;
}Expand description
Reads a typed view out of a parsed container.
The same reason as HasSchema, one step over. Each view’s inherent
from_gff carries its own error type, so a caller that does not already
know which view it wants cannot call it, and
GffDocument::view is exactly that caller.
A view that cannot fail names Infallible here.
§Only a whole file implements this
HasSchema is derived onto every modelled struct, nested ones included,
because a schema describes a struct at any depth. This is narrower on
purpose: a container has a magic and a nested struct does not, so only the
root of a format is here. That is what makes MAGIC a
question every implementor can answer.
Required Associated Constants§
Sourceconst MAGIC: [u8; 4]
const MAGIC: [u8; 4]
The four bytes a container of this format carries.
A GFF says what it is in its own first four bytes, so this is the file’s
claim about itself rather than anything about where it was found: it
survives a rename, storage in an archive under a resref, and being
carried inside a save. Extensions do not, and neither does
ResourceType, which has no entry at all
for the .res a save sidecar uses.
On the trait so it is declared once and read wherever it is needed: the view’s own reader refuses a container carrying something else, and a caller mapping a magic back to a schema looks it up. Two spellings of one magic is how those come to disagree.
Required Associated Types§
Required Methods§
Sourcefn from_gff(gff: &Gff) -> Result<Self, Self::Error>
fn from_gff(gff: &Gff) -> Result<Self, Self::Error>
Reads the view. Anything the view does not model stays in gff.
§Errors
Self::Error, on terms the implementing view decides. Every view in
this workspace refuses a container whose file type is not
Self::MAGIC, and otherwise reports only what the underlying GFF
read reports: a field of an unexpected type is taken where the type
tolerates it and dropped where it does not, rather than failing.
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.