forked from rust-lang/glacier
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |