pub trait Partial: Default + for<'a> From<&'a Self::Full> {
type Full;
fn build(self, stores: &Stores) -> Self::Full;
}Expand description
Implemented for partial objects
The API for partial objects follows a specific style:
- Partial objects are structs with fields that mirror the fields of the full object structs, but all fields are optional.
- Partial object structs have
with_*methods to provide values for each of their fields. - Partial object structs may have other methods with prefixes like
as_*,from_*, or similar, if one or more of their fields can be initialized by providing alternative data. - Partial object structs have a
buildmethod to build a full object. - All
with_*,as_*, andbuildmethods can be chained, to provide a convenient API.
Implementation Note
It would be nicer to require an Into bound instead of From (see
documentation of those types for more information). But I think we’d need a
where clause on the associated type to specify that, which is unstable. It
should become stable soon though, together with generic associated types:
https://github.com/rust-lang/rust/issues/44265
Required Associated Types
Required Methods
sourcefn build(self, stores: &Stores) -> Self::Full
fn build(self, stores: &Stores) -> Self::Full
Build a full object from this partial one
Implementations of this method will typically try to infer any missing parts of the partial object, but this is not possible in all cases. In such cases, implementations of this method may panic.
Calling build on a partial object that can’t infer its missing parts
is considered a programmer error, hence why this method doesn’t return a
Result.