1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::fmt::Debug;
use peace_resource_rt::{resources::ts::SetUp, Resources};
use serde::{de::DeserializeOwned, Serialize};
use crate::{AnySpecRt, ParamsResolveError, ValueResolutionCtx};
/// Runtime logic of how to look up values for each field in this struct.
///
/// This trait is automatically implemented by `#[derive(Params)]` on an
/// `Item::Params`, as well as manual implementations for standard library
/// types.
pub trait FieldWiseSpecRt: AnySpecRt {
/// The original value type. `MyParamsFieldWiseSpec::ValueType` is
/// `MyParams`.
type ValueType: Clone + Debug + Serialize + DeserializeOwned + Send + Sync + 'static;
/// The `Params` type, but with each of its fields wrapped in `Option`.
type Partial: Clone + Debug + Default + Serialize + DeserializeOwned + Send + Sync + 'static;
/// Resolves the values to construct the item `Params`.
///
/// This function returns an error if any value is not present in
/// [`Resources`]. For cases where missing values are not an error, see
/// [`resolve_partial`].
///
/// [`resolve_partial`]: Self::resolve_partial
fn resolve(
&self,
resources: &Resources<SetUp>,
value_resolution_ctx: &mut ValueResolutionCtx,
) -> Result<Self::ValueType, ParamsResolveError>;
/// Resolves the values to construct the item `Params`.
///
/// Values that are not present in `Resources` will be `None`.
fn resolve_partial(
&self,
resources: &Resources<SetUp>,
value_resolution_ctx: &mut ValueResolutionCtx,
) -> Result<Self::Partial, ParamsResolveError>;
}