Rename Action::Result to Action::Output
This commit is contained in:
parent
2bf19e0ea2
commit
742bd158f1
4 changed files with 8 additions and 7 deletions
|
|
@ -17,6 +17,7 @@ Procedure when bumping the version number:
|
||||||
- Error handling of `Action`s is now more complex but more powerful. In
|
- Error handling of `Action`s is now more complex but more powerful. In
|
||||||
particular, `Action`s can now return almost arbitrary errors without nesting
|
particular, `Action`s can now return almost arbitrary errors without nesting
|
||||||
`Result`s like before.
|
`Result`s like before.
|
||||||
|
- Renamed `Action::Result` to `Action::Output`
|
||||||
|
|
||||||
## v0.1.0 - 2023-02-12
|
## v0.1.0 - 2023-02-12
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@ use rusqlite::{Connection, Transaction};
|
||||||
/// Actions are usually passed to a vault which will then execute them and
|
/// Actions are usually passed to a vault which will then execute them and
|
||||||
/// return the result. The way in which this occurs depends on the vault.
|
/// return the result. The way in which this occurs depends on the vault.
|
||||||
pub trait Action {
|
pub trait Action {
|
||||||
type Result;
|
type Output;
|
||||||
type Error;
|
type Error;
|
||||||
fn run(self, conn: &mut Connection) -> Result<Self::Result, Self::Error>;
|
fn run(self, conn: &mut Connection) -> Result<Self::Output, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single database migration.
|
/// A single database migration.
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ impl SimpleVault {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute an [`Action`] and return the result.
|
/// Execute an [`Action`] and return the result.
|
||||||
pub fn execute<A: Action>(&mut self, action: A) -> Result<A::Result, A::Error> {
|
pub fn execute<A: Action>(&mut self, action: A) -> Result<A::Output, A::Error> {
|
||||||
action.run(&mut self.0)
|
action.run(&mut self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ trait ActionWrapper {
|
||||||
|
|
||||||
impl<T: Action> ActionWrapper for T
|
impl<T: Action> ActionWrapper for T
|
||||||
where
|
where
|
||||||
T::Result: Send + 'static,
|
T::Output: Send + 'static,
|
||||||
T::Error: Send + 'static,
|
T::Error: Send + 'static,
|
||||||
{
|
{
|
||||||
fn run(
|
fn run(
|
||||||
|
|
@ -133,10 +133,10 @@ impl TokioVault {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute an [`Action`] and return the result.
|
/// Execute an [`Action`] and return the result.
|
||||||
pub async fn execute<A>(&self, action: A) -> Result<A::Result, Error<A::Error>>
|
pub async fn execute<A>(&self, action: A) -> Result<A::Output, Error<A::Error>>
|
||||||
where
|
where
|
||||||
A: Action + Send + 'static,
|
A: Action + Send + 'static,
|
||||||
A::Result: Send,
|
A::Output: Send,
|
||||||
A::Error: Send,
|
A::Error: Send,
|
||||||
{
|
{
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
|
|
@ -153,7 +153,7 @@ impl TokioVault {
|
||||||
// always work.
|
// always work.
|
||||||
match result {
|
match result {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
let result = *result.downcast::<A::Result>().unwrap();
|
let result = *result.downcast::<A::Output>().unwrap();
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue