Crate peace_params

Source
Expand description

Constraints and specifications for parameters for the peace automation framework.

This crate defines types and traits for implementors and users to work with item params.

§Design

When an item is defined, implementors define the parameters type for that item.

For Peace to derive additional functionality from that type, this crate:

  • Defines the Params trait to bridge between the parameters type and associated types.
  • Re-exports the Params derive macro which implements the Params trait.

§How It Fits Together

.----------------------------------------------------------------------------------.
:          Users             :         Implementors           :       Peace        :
:----------------------------:--------------------------------:--------------------:
:                            :                                :                    :
:                            :   .-------------------.        :                    :
:                            :   | #[derive(Params)] |        : ---.               :
:                            :   | struct MyParams;  |        :    |               :
:                            :   '-------------------'        :    '               :
:                            :                                :  proc macro        :
:                            : .----------------------------. :  generates         :
:                            : | * MyParamsFieldWise        | :    .               :
:                            : | * MyParamsPartial          | :    |               :
:                            : | * MyParamsFieldWiseBuilder | : <--'               :
:                            : | * impl Params for MyParams | :                    :
:                            : '----------------------------' :                    :
:                            :                                :                    :
:                            :   .-------------------.        :                    :
:                            :   | struct MyItem;    |        :                    :
:                            :   |                   |        : ---.               :
:                            :   | impl Item for     |        :    |               :
:                            :   |   MyItem {        |        :    |               :
:                            :   |     type Params = |        :    '               :
:                            :   |     MyParams;     |        :  exposes API       :
:                            :   | }                 |        :  with constraints  :
:                            :   '-------------------'        :  from              :
:                            :                                :  <Item::Params     :
: .------------------------. :                                :    as Params>      :
: | cmd_ctx_builder        | :                                :    .               :
: | .with_item_params      | <-------------------------------------'               :
: |    ::<IS>(             | :                                :                    :
: |     item_id,           | :                                :                    :
: |     my_p_spec_builder  | :                                :                    :
: |       .with_f(123)     | :                                :                    :
: |       .with_from(..)   | :                                :                    :
: |     /* .build() */     | :                                :                    :
: |   )                    | :                                :                    :
: '------------------------' :                                :                    :
:                            :                                :                    :
'----------------------------------------------------------------------------------'

Re-exports§

pub use tynm;

Macros§

value_impl

Structs§

AnySpecRtBoxed
Box of a DataType that is also a [ValueSpecRt].
FieldNameAndType
A field name and its type.
MappingFnImpl
Wrapper around a mapping function so that it can be serialized.
ParamsSpecs
Map of item ID to its params’ specs. TypeMap<ItemId, AnySpecRtBoxed> newtype.
ValueResolutionCtx
Collects information about how a value is resolved.

Enums§

ParamsResolveError
Failed to resolve values for a Params object from resources.
ParamsSpec
How to populate a field’s value in an item’s params.
ParamsSpecDe
Exists to deserialize MappingFn with a non-type-erased MappingFnImpl
ParamsSpecFieldless
How to populate a field’s value in an item’s params.
ParamsSpecFieldlessDe
Exists to deserialize MappingFn with a non-type-erased MappingFnImpl
ValueResolutionMode
When resolving Values, whether to look up Current<T> or Goal<T>.
ValueSpec
How to populate a field’s value in an item’s params.
ValueSpecDe
Exists to deserialize MappingFn with a non-type-erased MappingFnImpl

Traits§

AnySpecDataType
A DataType that is also an AnySpecRt.
AnySpecRt
Runtime logic of how to look up values for each field in this struct.
FieldWiseSpecRt
Runtime logic of how to look up values for each field in this struct.
FromFunc
Provides a simpler constraint for the compiler to report to the developer.
Func
Provides a simpler constraint for the compiler to report to the developer.
MappingFn
Type erased mapping function.
Params
Input parameters to an item.
ParamsFieldless
Field of an Item::Params.
ParamsKey
Marker trait for a parameter key type.
ParamsMergeExt
Trait for merging ParamsPartial onto a Params object.
ParamsValue
Marker trait for a parameter value type.
ValueSpecRt
Runtime logic of how to look up values for each field in this struct.

Derive Macros§

Params
Used to #[derive] the ValueSpec and ValueSpecRt traits.
ParamsFieldless
Used to #[derive] the ParamsSpecFieldless and ValueSpecRt traits.