attribute_derive::from_partial

Trait FromPartial

Source
pub trait FromPartial<T>: Sized {
    // Required method
    fn from(partial: T) -> Result<Self>;

    // Provided methods
    fn from_option(partial: Option<T>, error_missing: &str) -> Result<Self> { ... }
    fn join(
        first: Option<SpannedValue<T>>,
        second: SpannedValue<T>,
        specified_twice_error: &str,
    ) -> Result<Option<SpannedValue<T>>> { ... }
}
Expand description

Converts from a Partial value.

Required Methods§

Source

fn from(partial: T) -> Result<Self>

Creates Self from T.

§Errors

Returns a syn::Error when T does not represent a valid Self, e.g., due to missing or conflicting fields.

Provided Methods§

Source

fn from_option(partial: Option<T>, error_missing: &str) -> Result<Self>

Creates Self from optional T.

§Errors

The default implementation errors with error_missing when partial is None, or when Self::from errors.

Implementors might override this for types with expected default values.

Source

fn join( first: Option<SpannedValue<T>>, second: SpannedValue<T>, specified_twice_error: &str, ) -> Result<Option<SpannedValue<T>>>

Defines how two arguments for the same parameter should be handled.

§Errors

The default implementation errors if first is already present and specified_twice_error is returned with the correct spans.

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.

Implementations on Foreign Types§

Source§

impl<T: FromPartial<P>, P> FromPartial<Partial<Option<P>>> for Option<T>

Source§

fn from(partial: Partial<Option<P>>) -> Result<Self>

Source§

impl<T: FromPartial<P>, P> FromPartial<Partial<Vec<P>>> for Vec<T>

Source§

fn from(partial: Partial<Vec<P>>) -> Result<Self>

Source§

fn join( first: Option<SpannedValue<Partial<Vec<P>>>>, second: SpannedValue<Partial<Vec<P>>>, _: &str, ) -> Result<Option<SpannedValue<Partial<Vec<P>>>>>

Implementors§