Skip to content

Commit

Permalink
Merge pull request #180 from azriel91/feature/179/remove-resources-ty…
Browse files Browse the repository at this point in the history
…pe-state-type-param
  • Loading branch information
azriel91 authored Jan 30, 2024
2 parents ca0f3ea + 23cb73c commit 3683183
Show file tree
Hide file tree
Showing 34 changed files with 107 additions and 226 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Add `Presenter::list_numbered_aligned` and `list_bulleted_aligned`. ([#151], [#178])
* Add `ListNumberedAligned`, `ListBulleted`, `ListBulletedAligned`. ([#151], [#178])
* Add `Either`, `PresentableExt`. ([#151], [#178])
* Remove `TS` type parameter from `SingleProfileSingleFlow` and `MultiProfileSingleFlow` scopes. ([#179], [#180])


[#172]: https://github.com/azriel91/peace/issues/172
Expand All @@ -21,6 +22,8 @@
[#177]: https://github.com/azriel91/peace/pull/177
[#151]: https://github.com/azriel91/peace/issues/151
[#178]: https://github.com/azriel91/peace/pull/178
[#179]: https://github.com/azriel91/peace/issues/179
[#180]: https://github.com/azriel91/peace/pull/180


## 0.0.12 (2023-12-30)
Expand Down
37 changes: 5 additions & 32 deletions crate/cmd/src/ctx/cmd_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

use std::ops::{Deref, DerefMut};

use peace_resources::Resources;
use peace_rt_model::Workspace;

use crate::{
ctx::{
cmd_ctx_builder::{
MultiProfileNoFlowBuilder, MultiProfileSingleFlowBuilder, NoProfileNoFlowBuilder,
SingleProfileNoFlowBuilder, SingleProfileSingleFlowBuilder,
},
CmdCtxBuilder, CmdCtxTypes,
use crate::ctx::{
cmd_ctx_builder::{
MultiProfileNoFlowBuilder, MultiProfileSingleFlowBuilder, NoProfileNoFlowBuilder,
SingleProfileNoFlowBuilder, SingleProfileSingleFlowBuilder,
},
scopes::SingleProfileSingleFlow,
CmdCtxBuilder, CmdCtxTypesCollectorEmpty,
};

use super::CmdCtxTypesCollectorEmpty;

/// Information needed to execute a command.
///
/// Importantly, as commands have different purposes, different command scopes
Expand Down Expand Up @@ -103,27 +97,6 @@ impl CmdCtx<()> {
}
}

impl<'ctx, CmdCtxTypesT, ResTs0> CmdCtx<SingleProfileSingleFlow<'ctx, CmdCtxTypesT, ResTs0>>
where
CmdCtxTypesT: CmdCtxTypes,
{
/// Updates `resources` to a different type state based on the given
/// function.
pub fn resources_update<ResTs1, F>(
self,
f: F,
) -> CmdCtx<SingleProfileSingleFlow<'ctx, CmdCtxTypesT, ResTs1>>
where
F: FnOnce(Resources<ResTs0>) -> Resources<ResTs1>,
{
let CmdCtx { scope } = self;

let scope = scope.resources_update(f);

CmdCtx { scope }
}
}

impl<Scope> Deref for CmdCtx<Scope> {
type Target = Scope;

Expand Down
30 changes: 15 additions & 15 deletions crate/cmd/src/scopes/multi_profile_single_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use crate::ctx::CmdCtxTypes;
/// * Read or write flow parameters for different flows.
/// * Read or write flow state for different flows.
#[derive(Debug)]
pub struct MultiProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
pub struct MultiProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
Expand Down Expand Up @@ -143,13 +143,13 @@ where
/// [`StatesGoalFile`]: peace_resources::paths::StatesGoalFile
states_type_reg: StatesTypeReg,
/// `Resources` for flow execution.
resources: Resources<TS>,
resources: Resources<SetUp>,
}

/// Access to fields in `MultiProfileSingleFlow` so that multiple borrows can
/// happen simultaneously.
#[derive(Debug)]
pub struct MultiProfileSingleFlowView<'view, CmdCtxTypesT, TS>
pub struct MultiProfileSingleFlowView<'view, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
Expand Down Expand Up @@ -219,10 +219,10 @@ where
/// [`StatesGoalFile`]: peace_resources::paths::StatesGoalFile
pub states_type_reg: &'view StatesTypeReg,
/// `Resources` for flow execution.
pub resources: &'view mut Resources<TS>,
pub resources: &'view mut Resources<SetUp>,
}

impl<'ctx, CmdCtxTypesT> MultiProfileSingleFlow<'ctx, CmdCtxTypesT, SetUp>
impl<'ctx, CmdCtxTypesT> MultiProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
Expand Down Expand Up @@ -282,14 +282,14 @@ where
}
}

impl<'ctx, CmdCtxTypesT, TS> MultiProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT> MultiProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
/// Returns a view struct of this scope.
///
/// This allows the flow and resources to be borrowed concurrently.
pub fn view(&mut self) -> MultiProfileSingleFlowView<'_, CmdCtxTypesT, TS> {
pub fn view(&mut self) -> MultiProfileSingleFlowView<'_, CmdCtxTypesT> {
let Self {
output,
interruptibility_state,
Expand Down Expand Up @@ -445,18 +445,18 @@ where
}

/// Returns a reference to the `Resources` for flow execution.
pub fn resources(&self) -> &Resources<TS> {
pub fn resources(&self) -> &Resources<SetUp> {
&self.resources
}

/// Returns a reference to the `Resources` for flow execution.
pub fn resources_mut(&mut self) -> &mut Resources<TS> {
pub fn resources_mut(&mut self) -> &mut Resources<SetUp> {
&mut self.resources
}
}

impl<'ctx, CmdCtxTypesT, TS, WorkspaceParamsK, ProfileParamsKMaybe, FlowParamsKMaybe>
MultiProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT, WorkspaceParamsK, ProfileParamsKMaybe, FlowParamsKMaybe>
MultiProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes<
ParamsKeys = ParamsKeysImpl<
Expand All @@ -476,8 +476,8 @@ where
}
}

impl<'ctx, CmdCtxTypesT, TS, WorkspaceParamsKMaybe, ProfileParamsK, FlowParamsKMaybe>
MultiProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT, WorkspaceParamsKMaybe, ProfileParamsK, FlowParamsKMaybe>
MultiProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes<
ParamsKeys = ParamsKeysImpl<
Expand All @@ -497,8 +497,8 @@ where
}
}

impl<'ctx, CmdCtxTypesT, TS, WorkspaceParamsKMaybe, ProfileParamsKMaybe, FlowParamsK>
MultiProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT, WorkspaceParamsKMaybe, ProfileParamsKMaybe, FlowParamsK>
MultiProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes<
ParamsKeys = ParamsKeysImpl<
Expand Down
92 changes: 18 additions & 74 deletions crate/cmd/src/scopes/single_profile_single_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use crate::ctx::CmdCtxTypes;
/// * Read or write flow state -- see `SingleProfileSingleFlow` or
/// `MultiProfileSingleFlow`.
#[derive(Debug)]
pub struct SingleProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
pub struct SingleProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
Expand Down Expand Up @@ -118,7 +118,7 @@ where
/// [`StatesGoalFile`]: peace_resources::paths::StatesGoalFile
states_type_reg: StatesTypeReg,
/// `Resources` for flow execution.
resources: Resources<TS>,
resources: Resources<SetUp>,
}

/// A command that works with one profile and one flow.
Expand Down Expand Up @@ -154,7 +154,7 @@ where
/// * Read or write flow state -- see `SingleProfileSingleFlow` or
/// `MultiProfileSingleFlow`.
#[derive(Debug)]
pub struct SingleProfileSingleFlowView<'view, CmdCtxTypesT, TS>
pub struct SingleProfileSingleFlowView<'view, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
Expand Down Expand Up @@ -211,7 +211,7 @@ where
/// [`StatesGoalFile`]: peace_resources::paths::StatesGoalFile
pub states_type_reg: &'view StatesTypeReg,
/// `Resources` for flow execution.
pub resources: &'view mut Resources<TS>,
pub resources: &'view mut Resources<SetUp>,
}

/// Split the output related parameters and the flow information.
Expand All @@ -221,7 +221,7 @@ where
/// `cmd_progress_tracker` mutably, while the flow information is passed through
/// to sub commands..
#[derive(Debug)]
pub struct SingleProfileSingleFlowViewAndOutput<'view, CmdCtxTypesT, TS>
pub struct SingleProfileSingleFlowViewAndOutput<'view, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
Expand All @@ -236,10 +236,10 @@ where
#[cfg(feature = "output_progress")]
pub cmd_progress_tracker: &'view mut peace_rt_model::CmdProgressTracker,
/// Flow and parameter related information.
pub cmd_view: SingleProfileSingleFlowView<'view, CmdCtxTypesT, TS>,
pub cmd_view: SingleProfileSingleFlowView<'view, CmdCtxTypesT>,
}

impl<'ctx, CmdCtxTypesT> SingleProfileSingleFlow<'ctx, CmdCtxTypesT, SetUp>
impl<'ctx, CmdCtxTypesT> SingleProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
Expand Down Expand Up @@ -294,14 +294,14 @@ where
}
}

impl<'ctx, CmdCtxTypesT, TS> SingleProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT> SingleProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes,
{
/// Returns a view struct of this scope.
///
/// This allows the flow and resources to be borrowed concurrently.
pub fn view(&mut self) -> SingleProfileSingleFlowView<'_, CmdCtxTypesT, TS> {
pub fn view(&mut self) -> SingleProfileSingleFlowView<'_, CmdCtxTypesT> {
let Self {
output: _,
interruptibility_state,
Expand Down Expand Up @@ -347,9 +347,7 @@ where
/// Returns a view and output struct of this scope.
///
/// This allows the flow and resources to be borrowed concurrently.
pub fn view_and_output(
&mut self,
) -> SingleProfileSingleFlowViewAndOutput<'_, CmdCtxTypesT, TS> {
pub fn view_and_output(&mut self) -> SingleProfileSingleFlowViewAndOutput<'_, CmdCtxTypesT> {
let Self {
output,
interruptibility_state,
Expand Down Expand Up @@ -508,72 +506,18 @@ where
}

/// Returns a reference to the `Resources` for flow execution.
pub fn resources(&self) -> &Resources<TS> {
pub fn resources(&self) -> &Resources<SetUp> {
&self.resources
}

/// Returns a reference to the `Resources` for flow execution.
pub fn resources_mut(&mut self) -> &mut Resources<TS> {
pub fn resources_mut(&mut self) -> &mut Resources<SetUp> {
&mut self.resources
}

/// Updates `resources` to a different type state based on the given
/// function.
pub fn resources_update<ResTs1, F>(
self,
f: F,
) -> SingleProfileSingleFlow<'ctx, CmdCtxTypesT, ResTs1>
where
F: FnOnce(Resources<TS>) -> Resources<ResTs1>,
{
let SingleProfileSingleFlow {
output,
interruptibility_state,
workspace,
#[cfg(feature = "output_progress")]
cmd_progress_tracker,
profile,
profile_dir,
profile_history_dir,
flow,
flow_dir,
params_type_regs,
workspace_params,
profile_params,
flow_params,
params_specs_type_reg,
params_specs,
states_type_reg,
resources,
} = self;

let resources = f(resources);

SingleProfileSingleFlow {
output,
interruptibility_state,
workspace,
#[cfg(feature = "output_progress")]
cmd_progress_tracker,
profile,
profile_dir,
profile_history_dir,
flow,
flow_dir,
params_type_regs,
workspace_params,
profile_params,
flow_params,
params_specs_type_reg,
params_specs,
states_type_reg,
resources,
}
}
}

impl<'ctx, CmdCtxTypesT, TS, WorkspaceParamsK, ProfileParamsKMaybe, FlowParamsKMaybe>
SingleProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT, WorkspaceParamsK, ProfileParamsKMaybe, FlowParamsKMaybe>
SingleProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes<
ParamsKeys = ParamsKeysImpl<
Expand All @@ -593,8 +537,8 @@ where
}
}

impl<'ctx, CmdCtxTypesT, TS, WorkspaceParamsKMaybe, ProfileParamsK, FlowParamsKMaybe>
SingleProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT, WorkspaceParamsKMaybe, ProfileParamsK, FlowParamsKMaybe>
SingleProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes<
ParamsKeys = ParamsKeysImpl<
Expand All @@ -614,8 +558,8 @@ where
}
}

impl<'ctx, CmdCtxTypesT, TS, WorkspaceParamsKMaybe, ProfileParamsKMaybe, FlowParamsK>
SingleProfileSingleFlow<'ctx, CmdCtxTypesT, TS>
impl<'ctx, CmdCtxTypesT, WorkspaceParamsKMaybe, ProfileParamsKMaybe, FlowParamsK>
SingleProfileSingleFlow<'ctx, CmdCtxTypesT>
where
CmdCtxTypesT: CmdCtxTypes<
ParamsKeys = ParamsKeysImpl<
Expand Down
2 changes: 1 addition & 1 deletion crate/cmd_rt/src/cmd_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub trait CmdBlock: Debug {
async fn exec(
&self,
input: Self::InputT,
cmd_view: &mut SingleProfileSingleFlowView<'_, Self::CmdCtxTypes, SetUp>,
cmd_view: &mut SingleProfileSingleFlowView<'_, Self::CmdCtxTypes>,
#[cfg(feature = "output_progress")] progress_tx: &Sender<CmdProgressUpdate>,
) -> Result<
CmdBlockOutcome<Self::Outcome, <Self::CmdCtxTypes as CmdCtxTypesConstrained>::AppError>,
Expand Down
3 changes: 1 addition & 2 deletions crate/cmd_rt/src/cmd_block/cmd_block_rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use async_trait::async_trait;

use peace_cmd::{ctx::CmdCtxTypesConstrained, scopes::SingleProfileSingleFlowView};
use peace_cmd_model::CmdBlockDesc;
use peace_resources::resources::ts::SetUp;

use crate::CmdBlockError;

Expand All @@ -28,7 +27,7 @@ pub trait CmdBlockRt: Debug + Unpin {
/// Executes this command block.
async fn exec(
&self,
view: &mut SingleProfileSingleFlowView<'_, Self::CmdCtxTypes, SetUp>,
view: &mut SingleProfileSingleFlowView<'_, Self::CmdCtxTypes>,
#[cfg(feature = "output_progress")] progress_tx: Sender<CmdProgressUpdate>,
) -> Result<
(),
Expand Down
Loading

0 comments on commit 3683183

Please sign in to comment.