Trait Buildable

Source
pub trait Buildable<Token> {
    type Output;
    type WrappedToken;

    // Required method
    fn build(this: Self) -> Self::Output;

    // Provided method
    fn prepare_build(builder: Self, _: &Token) -> PreBuild<Token, Self>
       where Self: Sized { ... }
}
Expand description

Trait finishing the builder and verifying all props were set. The structure can be a bit surprising, and is related to how the proc macro reports errors

  • why have a prepare_build method? This captures the argument types, but now How, and returns an internal type with a method that can be called without further qualification. We need the additional types, to avoid collision with property names in the Builder. We want to avoid qualification to persuade rust not to report the finish_build method name.
  • why have a AllPropsFor trait? We want the trait to be on the Token, not on a type associated or derived from it, so that it shows up in errors directly instead of through convoluted traces.

Required Associated Types§

Source

type Output

Property type being built

Source

type WrappedToken

Instead of Token directly, a wrapped token type is checked for trait impls in macro code. This avoids problems related to blanket impls.

Required Methods§

Source

fn build(this: Self) -> Self::Output

Build the props from self. Expected to panic if not all props where set.

Provided Methods§

Source

fn prepare_build(builder: Self, _: &Token) -> PreBuild<Token, Self>
where Self: Sized,

This method “captures” the builder and token type, but does not verify yet.

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.

Implementors§