Skip to content

Commit

Permalink
context: replace from_context
Browse files Browse the repository at this point in the history
  • Loading branch information
Nouzan committed Nov 26, 2023
1 parent b5374e3 commit 0ff211d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions crates/indicator/src/context/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ where
}

/// Declare that the data of type `D` is in the context.
// FIXME: this method should be removed in the future.
#[allow(clippy::wrong_self_convention)]
#[deprecated(note = "use `data_from_context` instead")]
fn from_context<D>(self) -> Stack<Self, AddData<D>>
where
D: Send + Sync + 'static,
Expand All @@ -259,6 +262,15 @@ where
self.with(AddData::<D>::from_context())
}

/// Declare that the data of type `D` is in the data context.
fn data_from_context<D>(self) -> Stack<Self, AddData<D>>
where
D: Send + Sync + 'static,
Self: Sized,
{
self.with(AddData::<D>::from_context())
}

/// Add a closure that will be called after the operator is evaluated.
fn then_with<Out, F, Builder>(self, builder: Builder) -> Stack<Self, Then<Builder>>
where
Expand Down
12 changes: 12 additions & 0 deletions crates/indicator/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ pub trait ContextOperatorExt<In>: ContextOperator<In> {
}

/// Declare that the data of type `D` is in the context.
// FIXME: this method should be removed in the future.
#[allow(clippy::wrong_self_convention)]
#[deprecated(note = "use `data_from_context` instead")]
fn from_context<D>(self) -> AddDataOperator<D, Self>
where
D: Send + Sync + 'static,
Expand All @@ -290,6 +293,15 @@ pub trait ContextOperatorExt<In>: ContextOperator<In> {
self.with(AddData::<D>::from_context())
}

/// Declare that the data of type `D` is in the data context.
fn data_from_context<D>(self) -> AddDataOperator<D, Self>
where
D: Send + Sync + 'static,
Self: Sized,
{
self.with(AddData::<D>::from_context())
}

/// Add a closure that will be called when the inner operator is evaluated.
fn then_with<Out, F, Builder>(self, builder: Builder) -> ThenOperator<Self, F>
where
Expand Down
2 changes: 1 addition & 1 deletion examples/context/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn main() -> anyhow::Result<()> {
println!("previous even count: {}", count.0);
}
})
.from_context::<&str>() // Asserting that the context has a `&str` data.
.data_from_context::<&str>() // Asserting that the context has a `&str` data.
.provide("This is my data!")
.insert_data(odds_counter)
.insert(even_signal::<bool, EvenCount>)
Expand Down

0 comments on commit 0ff211d

Please sign in to comment.