Rename Action::Result to Action::Output

This commit is contained in:
Joscha 2023-03-31 02:40:35 +02:00
parent 2bf19e0ea2
commit 742bd158f1
4 changed files with 8 additions and 7 deletions

View file

@ -17,6 +17,7 @@ Procedure when bumping the version number:
- Error handling of `Action`s is now more complex but more powerful. In
particular, `Action`s can now return almost arbitrary errors without nesting
`Result`s like before.
- Renamed `Action::Result` to `Action::Output`
## v0.1.0 - 2023-02-12

View file

@ -23,9 +23,9 @@ use rusqlite::{Connection, Transaction};
/// 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.
pub trait Action {
type Result;
type Output;
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.

View file

@ -52,7 +52,7 @@ impl SimpleVault {
}
/// 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)
}
}

View file

@ -20,7 +20,7 @@ trait ActionWrapper {
impl<T: Action> ActionWrapper for T
where
T::Result: Send + 'static,
T::Output: Send + 'static,
T::Error: Send + 'static,
{
fn run(
@ -133,10 +133,10 @@ impl TokioVault {
}
/// 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
A: Action + Send + 'static,
A::Result: Send,
A::Output: Send,
A::Error: Send,
{
let (tx, rx) = oneshot::channel();
@ -153,7 +153,7 @@ impl TokioVault {
// always work.
match result {
Ok(result) => {
let result = *result.downcast::<A::Result>().unwrap();
let result = *result.downcast::<A::Output>().unwrap();
Ok(result)
}
Err(err) => {