Skip to content

Commit

Permalink
async call
Browse files Browse the repository at this point in the history
  • Loading branch information
nrxus committed Mar 15, 2024
1 parent cba7f75 commit c46e76b
Show file tree
Hide file tree
Showing 6 changed files with 598 additions and 13 deletions.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
edition = "2021"
17 changes: 16 additions & 1 deletion src/faux_caller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ops::Deref, pin::Pin, rc::Rc, sync::Arc};
use std::{future::Future, ops::Deref, pin::Pin, rc::Rc, sync::Arc};

use crate::{Faux, MaybeFaux};

Expand All @@ -14,6 +14,21 @@ pub trait FauxCaller<R>: Sized {
real_fn(real, input)
}

async fn async_call<I, F: Future>(
self,
real_fn: fn(R, I) -> F,
fn_name: &'static str,
input: I,
) -> F::Output {
if let Some(fake) = self.try_as_faux() {
return unsafe { fake.async_foo(real_fn, fn_name, input) }.await;
}
let real = self
.try_into_real()
.expect("faux: bug! Should always be real");
real_fn(real, input).await
}

fn try_as_faux(&self) -> Option<&Faux>;
fn try_into_real(self) -> Option<R>;
}
Expand Down
Loading

0 comments on commit c46e76b

Please sign in to comment.