pub struct Fold<'a> { /* private fields */ }Expand description
Reading a whole settings struct out of one resolution.
Generated code reads each field in turn and calls Fold::finish once, which is what makes
the errors a list rather than the first thing that went wrong.
Implementations§
Source§impl Fold<'_>
impl Fold<'_>
Sourcepub fn optional<T: FromValue>(&mut self, id: PropId) -> Option<T>
pub fn optional<T: FromValue>(&mut self, id: PropId) -> Option<T>
A setting that may have no value, as Option<T>.
Absence is not an error here: a setting with no default and nothing set is a field that
holds None, which is what option<T> in the spec means.
Sourcepub fn required<T: FromValue>(&mut self, id: PropId) -> Option<T>
pub fn required<T: FromValue>(&mut self, id: PropId) -> Option<T>
A setting that must have a value, for a field that is not an Option.
Returns None only when it has recorded an error, so code that has already called
Fold::finish and found it Ok may unwrap what this returned. That is the contract
generated code is written against: the fold reports, and the struct is built afterwards.
Sourcepub fn errors(&self) -> &[ReadError]
pub fn errors(&self) -> &[ReadError]
What has gone wrong so far, for a caller that wants to add to the list.
Sourcepub fn finish(self) -> Result<(), ReadErrors>
pub fn finish(self) -> Result<(), ReadErrors>
Every setting read, or every reason one could not be.
Sourcepub fn into_errors(self) -> ReadErrors
pub fn into_errors(self) -> ReadErrors
Everything that went wrong, whether or not anything did.
What a lossy fold ends with: Fold::finish answers “did this work”, and the answer
there is always “not entirely” or the caller would not be folding lossily.