Skip to content

Commit

Permalink
A lot of string replacements to add <ItemIdT>.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Feb 1, 2024
1 parent 8c94293 commit cd338c2
Show file tree
Hide file tree
Showing 93 changed files with 960 additions and 680 deletions.
10 changes: 5 additions & 5 deletions crate/cfg/src/accessors/stored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use serde::Serialize;
pub struct Stored<'borrow, ItemIdT, T> {
/// ID of the item the state should be retrieved for.
item_id: ItemIdT,
/// The borrowed `StatesCurrentStored`.
states_current_stored: Option<Ref<'borrow, StatesCurrentStored>>,
/// The borrowed `StatesCurrentStored<ItemIdT>`.
states_current_stored: Option<Ref<'borrow, StatesCurrentStored<ItemIdT>>>,
/// Marker.
marker: PhantomData<T>,
}
Expand All @@ -47,7 +47,7 @@ where

fn borrow(item_id: &'borrow ItemIdT, resources: &'borrow Resources) -> Self {
let states_current_stored = resources
.try_borrow::<StatesCurrentStored>()
.try_borrow::<StatesCurrentStored<ItemIdT>>()
.map_err(|borrow_fail| match borrow_fail {
e @ BorrowFail::ValueNotFound => e,
BorrowFail::BorrowConflictImm | BorrowFail::BorrowConflictMut => {
Expand All @@ -70,7 +70,7 @@ impl<'borrow, ItemIdT, T> DataAccess for Stored<'borrow, ItemIdT, T> {
Self: Sized,
{
let mut type_ids = TypeIds::new();
type_ids.push(TypeId::of::<StatesCurrentStored>());
type_ids.push(TypeId::of::<StatesCurrentStored<ItemIdT>>());
type_ids
}

Expand All @@ -88,7 +88,7 @@ impl<'borrow, ItemIdT, T> DataAccessDyn for Stored<'borrow, ItemIdT, T> {
Self: Sized,
{
let mut type_ids = TypeIds::new();
type_ids.push(TypeId::of::<StatesCurrentStored>());
type_ids.push(TypeId::of::<StatesCurrentStored<ItemIdT>>());
type_ids
}

Expand Down
11 changes: 6 additions & 5 deletions crate/cmd/src/scopes/multi_profile_single_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::ctx::CmdCtxTypes;
/// | |- 🌊 deploy # ✅ can read `FlowId`
/// | | |- 📝 flow_params.yaml # ✅ can read or write `FlowParams`
/// | | |- 📋 states_goal.yaml # ✅ can read or write `StatesGoal`
/// | | |- 📋 states_current.yaml # ✅ can read or write `StatesCurrentStored`
/// | | |- 📋 states_current.yaml # ✅ can read or write `StatesCurrentStored<ItemIdT>`
/// | |
/// | |- 🌊 .. # ❌ cannot read or write other `Flow` information
/// |
Expand Down Expand Up @@ -124,7 +124,7 @@ where
FlowParams<<<CmdCtxTypesT::ParamsKeys as ParamsKeys>::FlowParamsKMaybe as KeyMaybe>::Key>,
>,
/// Stored current states for each profile for the selected flow.
profile_to_states_current_stored: BTreeMap<Profile, Option<StatesCurrentStored>>,
profile_to_states_current_stored: BTreeMap<Profile, Option<StatesCurrentStored<ItemIdT>>>,
/// Type registry for each item's [`Params`]`::Spec`.
///
/// This is used to deserialize [`ParamsSpecsFile`].
Expand Down Expand Up @@ -200,7 +200,8 @@ where
FlowParams<<<CmdCtxTypesT::ParamsKeys as ParamsKeys>::FlowParamsKMaybe as KeyMaybe>::Key>,
>,
/// Stored current states for each profile for the selected flow.
pub profile_to_states_current_stored: &'view BTreeMap<Profile, Option<StatesCurrentStored>>,
pub profile_to_states_current_stored:
&'view BTreeMap<Profile, Option<StatesCurrentStored<ItemIdT>>>,
/// Type registry for each item's [`Params`]`::Spec`.
///
/// This is used to deserialize [`ParamsSpecsFile`].
Expand Down Expand Up @@ -253,7 +254,7 @@ where
<<CmdCtxTypesT::ParamsKeys as ParamsKeys>::FlowParamsKMaybe as KeyMaybe>::Key,
>,
>,
profile_to_states_current_stored: BTreeMap<Profile, Option<StatesCurrentStored>>,
profile_to_states_current_stored: BTreeMap<Profile, Option<StatesCurrentStored<ItemIdT>>>,
params_specs_type_reg: ParamsSpecsTypeReg,
profile_to_params_specs: BTreeMap<Profile, Option<ParamsSpecs>>,
states_type_reg: StatesTypeReg,
Expand Down Expand Up @@ -413,7 +414,7 @@ where
/// flow.
pub fn profile_to_states_current_stored(
&self,
) -> &BTreeMap<Profile, Option<StatesCurrentStored>> {
) -> &BTreeMap<Profile, Option<StatesCurrentStored<ItemIdT>>> {
&self.profile_to_states_current_stored
}

Expand Down
4 changes: 2 additions & 2 deletions crate/cmd/src/scopes/single_profile_single_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::ctx::CmdCtxTypes;
/// | |- 🌊 deploy # ✅ can read `FlowId`
/// | | |- 📝 flow_params.yaml # ✅ can read or write `FlowParams`
/// | | |- 📋 states_goal.yaml # ✅ can read or write `StatesGoal`
/// | | |- 📋 states_current.yaml # ✅ can read or write `StatesCurrentStored`
/// | | |- 📋 states_current.yaml # ✅ can read or write `StatesCurrentStored<ItemIdT>`
/// | |
/// | |- 🌊 .. # ❌ cannot read or write other `Flow` information
/// |
Expand Down Expand Up @@ -133,7 +133,7 @@ where
/// | |- 🌊 deploy # ✅ can read `FlowId`
/// | | |- 📝 flow_params.yaml # ✅ can read or write `FlowParams`
/// | | |- 📋 states_goal.yaml # ✅ can read or write `StatesGoal`
/// | | |- 📋 states_current.yaml # ✅ can read or write `StatesCurrentStored`
/// | | |- 📋 states_current.yaml # ✅ can read or write `StatesCurrentStored<ItemIdT>`
/// | |
/// | |- 🌊 .. # ❌ cannot read or write other `Flow` information
/// |
Expand Down
2 changes: 1 addition & 1 deletion crate/cmd_model/src/cmd_block_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl CmdBlockDesc {
}

/// Returns the short type names of `CmdBlock::InputT`, e.g.
/// `["States<Current>", "States<Goal>"]`.
/// `["States<ItemIdT, Current>", "States<ItemIdT, Goal>"]`.
///
/// * If `InputT` is the unit struct `()`, this should be empty.
/// * If `InputT` is a named struct, this should contain just one `String`.
Expand Down
28 changes: 14 additions & 14 deletions crate/cmd_model/src/cmd_execution_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use crate::CmdBlockDesc;
pub enum CmdExecutionError {
/// Error fetching `CmdBlock::InputT` from `resources`.
///
/// If `CmdBlock::InputT` is a tuple, such as `(StatesCurrent, StatesGoal)`,
/// and `states_current` and `states_goal` are inserted individually in
/// `Resources`, then `CmdBlock::input_fetch` should be implemented to call
/// `Resources::remove` for each of them.
/// If `CmdBlock::InputT` is a tuple, such as `(StatesCurrent<ItemIdT>,
/// StatesGoal<ItemIdT>)`, and `states_current` and `states_goal` are
/// inserted individually in `Resources`, then `CmdBlock::input_fetch`
/// should be implemented to call `Resources::remove` for each of them.
#[error(
"Error in `CmdExecution` or `CmdBlock` logic, usually due to incorrect `Resource` insertion or removal."
)]
Expand Down Expand Up @@ -44,23 +44,23 @@ pub enum CmdExecutionError {
///
/// ```yaml
/// CmdExecution:
/// ExecutionOutcome: (States<Previous>, States<Ensured>, States<Goal>)
/// ExecutionOutcome: (States<ItemIdT, Previous>, States<ItemIdT, Ensured>, States<ItemIdT, Goal>)
/// CmdBlocks:
/// - StatesCurrentReadCmdBlock:
/// Input: States<Current>
/// Outcome: States<Goal>
/// Input: States<ItemIdT, Current>
/// Outcome: States<ItemIdT, Goal>
/// - StatesGoalReadCmdBlock:
/// Input: States<Current>
/// Outcome: States<Goal>
/// Input: States<ItemIdT, Current>
/// Outcome: States<ItemIdT, Goal>
/// - StatesDiscoverCmdBlock:
/// Input: ()
/// Outcome: (States<Current>, States<Goal>)
/// Outcome: (States<ItemIdT, Current>, States<ItemIdT, Goal>)
/// - ApplyStateSyncCheckCmdBlock:
/// Input: (States<CurrentStored>, States<Current>, States<GoalStored>, States<Goal>)
/// Outcome: (States<CurrentStored>, States<Current>, States<GoalStored>, States<Goal>)
/// Input: (States<ItemIdT, CurrentStored>, States<ItemIdT, Current>, States<ItemIdT, GoalStored>, States<ItemIdT, Goal>)
/// Outcome: (States<ItemIdT, CurrentStored>, States<ItemIdT, Current>, States<ItemIdT, GoalStored>, States<ItemIdT, Goal>)
/// - ApplyExecCmdBlock:
/// Input: (States<Current>, States<Goal>)
/// Outcome: (States<Previous>, States<Ensured>, States<Goal>)
/// Input: (States<ItemIdT, Current>, States<ItemIdT, Goal>)
/// Outcome: (States<ItemIdT, Previous>, States<ItemIdT, Ensured>, States<ItemIdT, Goal>)
/// ```
#[cfg(feature = "error_reporting")]
#[source_code]
Expand Down
27 changes: 14 additions & 13 deletions crate/cmd_rt/src/cmd_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ pub trait CmdBlock: Debug {
///
/// `CmdBlock` uses the `AppError` and `ParamsKeys` associated type.
type CmdCtxTypes: CmdCtxTypesConstrained;
/// Outcome type of the command block, e.g. `(StatesCurrent, StatesGoal)`.
/// Outcome type of the command block, e.g. `(StatesCurrent<ItemIdT>,
/// StatesGoal<ItemIdT>)`.
type Outcome: Debug + Send + Sync + 'static;
/// Input type of the command block, e.g. `StatesCurrent`.
type InputT: Resource + 'static;
Expand Down Expand Up @@ -91,20 +92,20 @@ pub trait CmdBlock: Debug {
/// Within the `peace` framework:
///
/// ```rust,ignore
/// // type InputT = (StatesCurrent, StatesGoal);
/// // type InputT = (StatesCurrent<ItemIdT>, StatesGoal<ItemIdT>);
///
/// vec![tynm::type_name::<StatesCurrent>(),
/// tynm::type_name::<StatesGoal>()]
/// vec![tynm::type_name::<StatesCurrent<ItemIdT>>(),
/// tynm::type_name::<StatesGoal<ItemIdT>>()]
/// ```
///
/// Outside the `peace` framework:
///
/// ```rust,ignore
/// // type InputT = (StatesCurrent, StatesGoal);
/// // type InputT = (StatesCurrent<ItemIdT>, StatesGoal<ItemIdT>);
///
/// vec![
/// peace::cmd_rt::tynm::type_name::<StatesCurrent>(),
/// peace::cmd_rt::tynm::type_name::<StatesGoal>(),
/// peace::cmd_rt::tynm::type_name::<StatesCurrent<ItemIdT>>(),
/// peace::cmd_rt::tynm::type_name::<StatesGoal<ItemIdT>>(),
/// ]
/// ```
fn input_type_names(&self) -> Vec<String> {
Expand Down Expand Up @@ -140,20 +141,20 @@ pub trait CmdBlock: Debug {
/// Within the `peace` framework:
///
/// ```rust,ignore
/// // type Outcome = (StatesCurrent, StatesGoal);
/// // type Outcome = (StatesCurrent<ItemIdT>, StatesGoal<ItemIdT>);
///
/// vec![tynm::type_name::<StatesCurrent>(),
/// tynm::type_name::<StatesGoal>()]
/// vec![tynm::type_name::<StatesCurrent<ItemIdT>>(),
/// tynm::type_name::<StatesGoal<ItemIdT>>()]
/// ```
///
/// Outside the `peace` framework:
///
/// ```rust,ignore
/// // type Outcome = (StatesCurrent, StatesGoal);
/// // type Outcome = (StatesCurrent<ItemIdT>, StatesGoal<ItemIdT>);
///
/// vec![
/// peace::cmd_rt::tynm::type_name::<StatesCurrent>(),
/// peace::cmd_rt::tynm::type_name::<StatesGoal>(),
/// peace::cmd_rt::tynm::type_name::<StatesCurrent<ItemIdT>>(),
/// peace::cmd_rt::tynm::type_name::<StatesGoal<ItemIdT>>(),
/// ]
/// ```
fn outcome_type_names(&self) -> Vec<String> {
Expand Down
8 changes: 4 additions & 4 deletions crate/cmd_rt/src/cmd_block/cmd_block_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ where
{
/// Error fetching `CmdBlock::InputT` from `resources`.
///
/// If `CmdBlock::InputT` is a tuple, such as `(StatesCurrent, StatesGoal)`,
/// and `states_current` and `states_goal` are inserted individually in
/// `Resources`, then `CmdBlock::input_fetch` should be implemented to call
/// `Resources::remove` for each of them.
/// If `CmdBlock::InputT` is a tuple, such as `(StatesCurrent<ItemIdT>,
/// StatesGoal<ItemIdT>)`, and `states_current` and `states_goal` are
/// inserted individually in `Resources`, then `CmdBlock::input_fetch`
/// should be implemented to call `Resources::remove` for each of them.
#[error(
"Failed to fetch `{input_name_short}` from `resource`s.",
input_name_short = _0.resource_name_short
Expand Down
3 changes: 2 additions & 1 deletion crate/cmd_rt/src/cmd_block/cmd_block_rt_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::CmdBlockRt;
///
/// * `E`: Automation software error type.
/// * `PKeys`: Types of params keys.
/// * `Outcome`: [`CmdBlock`] outcome type, e.g. `(StatesCurrent, StatesGoal)`.
/// * `Outcome`: [`CmdBlock`] outcome type, e.g. `(StatesCurrent<ItemIdT>,
/// StatesGoal<ItemIdT>)`.
///
/// [`CmdBlock`]: crate::CmdBlock
pub type CmdBlockRtBox<'types, CmdCtxTypesT, ExecutionOutcome> = Pin<
Expand Down
4 changes: 2 additions & 2 deletions crate/cmd_rt/src/cmd_block/cmd_block_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ where
// If possible, `CmdBlock` outcomes with item errors need to be mapped to
// the `CmdExecution` outcome type, so we still return the item errors.
//
// e.g. `StatesCurrentMut` should be mapped into `StatesEnsured` when some
// items fail to be ensured.
// e.g. `StatesCurrentMut` should be mapped into `StatesEnsured<ItemIdT>` when
// some items fail to be ensured.
//
// Note, when discovering current and goal states for diffing, and an item
// error occurs, mapping the partially accumulated `(StatesCurrentMut,
Expand Down
20 changes: 10 additions & 10 deletions crate/cmd_rt/src/cmd_execution/cmd_execution_error_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ impl CmdExecutionErrorBuilder {
///
/// ```yaml
/// CmdExecution:
/// ExecutionOutcome: (States<Previous>, States<Ensured>, States<Goal>)
/// ExecutionOutcome: (States<ItemIdT, Previous>, States<ItemIdT, Ensured>, States<ItemIdT, Goal>)
/// CmdBlocks:
/// - StatesCurrentReadCmdBlock:
/// Input: States<Current>
/// Outcome: States<Goal>
/// Input: States<ItemIdT, Current>
/// Outcome: States<ItemIdT, Goal>
/// - StatesGoalReadCmdBlock:
/// Input: States<Current>
/// Outcome: States<Goal>
/// Input: States<ItemIdT, Current>
/// Outcome: States<ItemIdT, Goal>
/// - StatesDiscoverCmdBlock:
/// Input: ()
/// Outcome: (States<Current>, States<Goal>)
/// Outcome: (States<ItemIdT, Current>, States<ItemIdT, Goal>)
/// - ApplyStateSyncCheckCmdBlock:
/// Input: (States<CurrentStored>, States<Current>, States<GoalStored>, States<Goal>)
/// Outcome: (States<CurrentStored>, States<Current>, States<GoalStored>, States<Goal>)
/// Input: (States<ItemIdT, CurrentStored>, States<ItemIdT, Current>, States<ItemIdT, GoalStored>, States<ItemIdT, Goal>)
/// Outcome: (States<ItemIdT, CurrentStored>, States<ItemIdT, Current>, States<ItemIdT, GoalStored>, States<ItemIdT, Goal>)
/// - ApplyExecCmdBlock:
/// Input: (States<Current>, States<Goal>)
/// Outcome: (States<Previous>, States<Ensured>, States<Goal>)
/// Input: (States<ItemIdT, Current>, States<ItemIdT, Goal>)
/// Outcome: (States<ItemIdT, Previous>, States<ItemIdT, Ensured>, States<ItemIdT, Goal>)
/// ```
pub fn build<'types: 'f, 'f, ExecutionOutcome, CmdCtxTypesT, CmdBlockIterator>(
cmd_blocks: CmdBlockIterator,
Expand Down
14 changes: 7 additions & 7 deletions crate/code_gen/src/cmd/impl_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,14 @@ fn impl_build_for(
// &states_current_file,
// )
// .await?
// .map(Into::<peace_resources::states::StatesCurrentStored>::into);
// .map(Into::<peace_resources::states::StatesCurrentStored::<ItemIdT>>::into);
//
// Ok((profile.clone(), states_current_stored))
// })
// .try_collect::<
// std::collections::BTreeMap<
// peace_core::Profile,
// Option<peace_resources::states::StatesCurrentStored>
// Option<peace_resources::states::StatesCurrentStored<ItemIdT>>
// >
// >()
// .await?;
Expand Down Expand Up @@ -715,7 +715,7 @@ fn impl_build_for(
// &states_current_file,
// )
// .await?
// .map(Into::<peace_resources::states::StatesCurrentStored>::into);
// .map(Into::<peace_resources::states::StatesCurrentStored::<ItemIdT>>::into);
// if let Some(states_current_stored) = states_current_stored {
// resources.insert(states_current_stored);
// }
Expand Down Expand Up @@ -1542,7 +1542,7 @@ fn states_and_params_read_and_pg_init(scope: Scope) -> proc_macro2::TokenStream
Scope::MultiProfileSingleFlow => {
// * Reads previous item params and stores them in a `Map<Profile, ItemParams>`.
// * Reads previously stored current states and stores them in a `Map<Profile,
// StatesCurrentStored>`.
// StatesCurrentStored<ItemIdT>>`.
//
// These are then held in the scope for easy access for consumers.
quote! {
Expand Down Expand Up @@ -1617,14 +1617,14 @@ fn states_and_params_read_and_pg_init(scope: Scope) -> proc_macro2::TokenStream
&states_current_file,
)
.await?
.map(Into::<peace_resources::states::StatesCurrentStored>::into);
.map(Into::<peace_resources::states::StatesCurrentStored::<ItemIdT>>::into);

Ok((profile.clone(), states_current_stored))
})
.try_collect::<
std::collections::BTreeMap<
peace_core::Profile,
Option<peace_resources::states::StatesCurrentStored>
Option<peace_resources::states::StatesCurrentStored<ItemIdT>>
>
>()
.await?;
Expand Down Expand Up @@ -1701,7 +1701,7 @@ fn states_and_params_read_and_pg_init(scope: Scope) -> proc_macro2::TokenStream
&states_current_file,
)
.await?
.map(Into::<peace_resources::states::StatesCurrentStored>::into);
.map(Into::<peace_resources::states::StatesCurrentStored::<ItemIdT>>::into);
if let Some(states_current_stored) = states_current_stored {
resources.insert(states_current_stored);
}
Expand Down
11 changes: 4 additions & 7 deletions crate/core/src/progress/progress_sender.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use tokio::sync::mpsc::Sender;

use crate::{
progress::{
CmdProgressUpdate, ProgressDelta, ProgressMsgUpdate, ProgressUpdate, ProgressUpdateAndId,
},
ItemIdT,
use crate::progress::{
CmdProgressUpdate, ProgressDelta, ProgressMsgUpdate, ProgressUpdate, ProgressUpdateAndId,
};

/// Submits progress for an item's `ApplyFns::exec` method.
#[derive(Clone, Copy, Debug)]
pub struct ProgressSender<'exec> {
pub struct ProgressSender<'exec, ItemIdT> {
/// ID of the item this belongs to.
item_id: &'exec ItemIdT,
/// Channel sender to send progress updates to.
progress_tx: &'exec Sender<CmdProgressUpdate>,
}

impl<'exec> ProgressSender<'exec> {
impl<'exec, ItemIdT> ProgressSender<'exec, ItemIdT> {
/// Returns a new `ProgressSender`.
pub fn new(item_id: &'exec ItemIdT, progress_tx: &'exec Sender<CmdProgressUpdate>) -> Self {
Self {
Expand Down
7 changes: 2 additions & 5 deletions crate/core/src/progress/progress_update_and_id.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use serde::{Deserialize, Serialize};

use crate::{
progress::{ProgressMsgUpdate, ProgressUpdate},
ItemIdT,
};
use crate::progress::{ProgressMsgUpdate, ProgressUpdate};

/// An item ID and its progress update.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct ProgressUpdateAndId {
pub struct ProgressUpdateAndId<ItemIdT> {
/// ID of the item whose progress is updated.
pub item_id: ItemIdT,
/// Delta update for the progress tracker.
Expand Down
Loading

0 comments on commit cd338c2

Please sign in to comment.