ParamsSpecFieldless

Enum ParamsSpecFieldless 

Source
pub enum ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static,
{ Stored, Value { value: T, }, InMemory, MappingFn(Box<dyn MappingFn<Output = T>>), }
Expand description

How to populate a field’s value in an item’s params.

The MappingFn variant’s mapping function is None when deserialized, as it is impossible to determine the underlying F and U type parameters for the backing MappingFnImpl.

For deserialization:

  1. A ParamsSpecsTypeReg is constructed, and deserialization functions are registered from ItemId to ParamsSpecFieldlessDe<T, F, U>, where F and U are derived from the ValueSpec provided by the user.

  2. value_specs.yaml is deserialized using that type registry.

  3. Each ParamsSpecFieldlessDe<T> is mapped into a ParamsSpecFieldless<T>, and subsequently AnySpecRtBoxed to be passed around in a CmdCtx.

  4. These AnySpecRtBoxeds are downcasted back to ParamsSpecFieldless<T> when resolving values for item params and params partials.

Variants§

§

Stored

Loads a stored value spec.

The value used is determined by the value spec that was last stored in the params_specs_file. This means it could be loaded as a Value(T) during context build().

This variant may be provided when defining a command context builder. However, this variant is never serialized, but whichever value was first stored is re-loaded then re-serialized.

If no value spec was previously serialized, then the command context build will return an error.

§

Value

Uses the provided value.

The value used is whatever is passed in to the command context builder.

Fields

§value: T

The value to use.

§

InMemory

Uses a value loaded from resources at runtime.

The value may have been provided by workspace params, or inserted by a predecessor at runtime.

§

MappingFn(Box<dyn MappingFn<Output = T>>)

Uses a mapped value loaded from resources at runtime.

The value may have been provided by workspace params, or inserted by a predecessor at runtime, and is mapped by the given function.

This is serialized as MappingFn with a string value. For deserialization, there is no actual backing function, so the user must provide the MappingFn in subsequent command context builds.

Implementations§

Source§

impl<T> ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static,

Source

pub fn from_map<F, Args>(field_name: Option<String>, f: F) -> Self
where MappingFnImpl<T, F, Args>: From<(Option<String>, F)> + MappingFn<Output = T>,

Source§

impl<T> ParamsSpecFieldless<T>
where T: ParamsFieldless<Spec = ParamsSpecFieldless<T>> + Clone + Debug + Send + Sync + 'static, T::Partial: From<T>,

Source

pub fn resolve( &self, resources: &Resources<SetUp>, value_resolution_ctx: &mut ValueResolutionCtx, ) -> Result<T, ParamsResolveError>

Source

pub fn resolve_partial( &self, resources: &Resources<SetUp>, value_resolution_ctx: &mut ValueResolutionCtx, ) -> Result<T::Partial, ParamsResolveError>

Trait Implementations§

Source§

impl<T> AnySpecRt for ParamsSpecFieldless<T>
where T: ParamsFieldless<Spec = ParamsSpecFieldless<T>> + Clone + Debug + Serialize + Send + Sync + 'static,

Source§

fn is_usable(&self) -> bool

Whether this Spec is usable to resolve values. Read more
Source§

fn merge(&mut self, other_boxed: &dyn AnySpecDataType)
where Self: Sized,

Deep merges the provided AnySpecRt with self, where self takes priority, except for Self::Stored. Read more
Source§

impl<T> Clone for ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static + Clone,

Source§

fn clone(&self) -> ParamsSpecFieldless<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, T> Deserialize<'de> for ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static + Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> From<ParamsSpecFieldlessDe<T>> for ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static,

Source§

fn from(value_spec_de: ParamsSpecFieldlessDe<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T> Serialize for ParamsSpecFieldless<T>
where T: ParamsFieldless + Clone + Debug + Send + Sync + 'static + Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> ValueSpecRt for ParamsSpecFieldless<T>
where T: ParamsFieldless<Spec = ParamsSpecFieldless<T>> + Clone + Debug + Serialize + Send + Sync + 'static + TryFrom<T::Partial>, T::Partial: From<T>,

Source§

type ValueType = T

The original value type. MyParamsValueSpec::ValueType is MyParams.
Source§

fn resolve( &self, resources: &Resources<SetUp>, value_resolution_ctx: &mut ValueResolutionCtx, ) -> Result<T, ParamsResolveError>

Resolves the value from resources. Read more
Source§

fn try_resolve( &self, resources: &Resources<SetUp>, value_resolution_ctx: &mut ValueResolutionCtx, ) -> Result<Option<T>, ParamsResolveError>

Resolves the value from resources, returning None if it is not present.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DataType for T
where T: Any + DynClone + Debug + Serialize + Send + Sync,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Resource for T
where T: Any + Debug + Send + Sync,

Source§

fn type_id(&self) -> TypeId

Source§

fn type_name(&self) -> TypeNameLit

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AnySpecDataType for T
where T: Any + DynClone + Debug + AnySpecRt + Serialize + Send + Sync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,