Skip to content

Commit

Permalink
Add issue-80706
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Jan 15, 2021
1 parent 7128247 commit 04220b0
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions ices/80706.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
type BoxFuture<T> = std::pin::Pin<Box<dyn std::future::Future<Output = T>>>;

fn main() {
let _ = f();
}

async fn f() {
run("dependency").await;
}

struct InMemoryStorage;

pub struct User<'dep> {
pub dep: &'dep str,
}

impl<'a> StorageRequest<InMemoryStorage> for SaveUser<'a> {
fn execute(&self) -> BoxFuture<Result<(), String>> {
todo!()
}
}

trait Storage {
type Error;
}

impl Storage for InMemoryStorage {
type Error = String;
}

trait StorageRequestReturnType {
type Output;
}

trait StorageRequest<S: Storage>: StorageRequestReturnType {
fn execute(
&self,
) -> BoxFuture<Result<<Self as StorageRequestReturnType>::Output, <S as Storage>::Error>>;
}

pub struct SaveUser<'a> {
pub name: &'a str,
}

impl<'a> StorageRequestReturnType for SaveUser<'a> {
type Output = ();
}

impl<'dep> User<'dep> {
async fn save<S>(self)
where
S: Storage,
for<'a> SaveUser<'a>: StorageRequest<S>,
{
let _ = SaveUser { name: "Joe" }.execute().await;
}
}

async fn run<S>(dep: &str)
where
S: Storage,
for<'a> SaveUser<'a>: StorageRequest<S>,
{
User { dep }.save().await;
}

0 comments on commit 04220b0

Please sign in to comment.