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.
  • Values provided to with_* are usually wrapped in an Option, and only a Some(...) value has any effect. This is a trade-off that makes most use cases slightly more verbose, while significantly simplifying more complex use cases.
  • 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 build method to build a full object.
  • All with_*, as_*, and build methods 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

The type representing the full variant of this object

Required Methods

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.

Implementors