Last active
August 27, 2019 22:47
-
-
Save davidbarsky/0f9bc182df2e54365b4d208b42a083e2 to your computer and use it in GitHub Desktop.
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
#![feature(async_await)] | |
use failure::{Fail, Error}; | |
use std::future::Future; | |
use std::pin::Pin; | |
/// `S3Request` is a trait that specifies: | |
/// - the service request/response pairing. | |
/// - the service protocol (json, rest-json, rest-xml, or query) | |
/// - optionally, additional metadata. | |
/// - mechanisms of serializing/deserializing this data | |
/// - where the request should be routed. | |
/// In summary, S3Request is a trait encodes shows how | |
/// a Botocore object can be transformer into an `http::Request<hyper::Body>`, | |
/// and how the resulting `http::Response<hyper::Body>` can be transformed | |
/// into a typed Botocore object. | |
trait AWSResource { | |
type Response; | |
} | |
struct GetObjectRequest; | |
struct GetObjectResponse; | |
#[derive(Fail, Debug)] | |
#[fail(display = "invalid toolchain name")] | |
struct GetObjectError; | |
impl AWSResource for GetObjectRequest { | |
type Response = Result<GetObjectResponse, GetObjectError>; | |
} | |
type Fut<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>; | |
struct S3; | |
impl S3 { | |
fn call<T>(&self, _: T) -> Fut<T::Response> | |
where | |
T: AWSResource, | |
{ | |
unimplemented!() | |
} | |
} | |
async fn run() -> Result<(), Error> { | |
let s3 = S3; | |
let _: GetObjectResponse = s3.call(GetObjectRequest).await?; | |
Ok(()) | |
} | |
fn main() { | |
// assume this is spawned to tokio, romio, or https://github.com/rustasync/runtime. | |
let _res = run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment