From d6f18163837e0c05e9075aedfe0059cf23ddc4bc Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Tue, 22 Nov 2022 23:31:28 +0100 Subject: [PATCH] add new example to reprodue a rust issue Signed-off-by: Vincenzo Palazzo --- Cargo.lock | 7 +++++ Cargo.toml | 3 +- examples/lifetime_issue/Cargo.toml | 7 +++++ examples/lifetime_issue/src/future.rs | 39 +++++++++++++++++++++++++ examples/lifetime_issue/src/main.rs | 14 +++++++++ examples/lifetime_issue/src/services.rs | 37 +++++++++++++++++++++++ 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 examples/lifetime_issue/Cargo.toml create mode 100644 examples/lifetime_issue/src/future.rs create mode 100644 examples/lifetime_issue/src/main.rs create mode 100644 examples/lifetime_issue/src/services.rs diff --git a/Cargo.lock b/Cargo.lock index 66e83a0..9e79840 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1109,6 +1109,13 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "lifetime_issue" +version = "0.1.0" +dependencies = [ + "rio_rt", +] + [[package]] name = "link-cplusplus" version = "1.0.7" diff --git a/Cargo.toml b/Cargo.toml index 02e4568..f785398 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,6 @@ members = [ "io", "lib", "rt", - "examples/rio_triage_await" + "examples/rio_triage_await", + "examples/lifetime_issue", ] diff --git a/examples/lifetime_issue/Cargo.toml b/examples/lifetime_issue/Cargo.toml new file mode 100644 index 0000000..abc607c --- /dev/null +++ b/examples/lifetime_issue/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "lifetime_issue" +version = "0.1.0" +edition = "2021" + +[dependencies] +rio_rt = { path = "../../rt" } diff --git a/examples/lifetime_issue/src/future.rs b/examples/lifetime_issue/src/future.rs new file mode 100644 index 0000000..d8d83dd --- /dev/null +++ b/examples/lifetime_issue/src/future.rs @@ -0,0 +1,39 @@ +use std::future::Future; +use std::pin::Pin; +use std::task::Context; +use std::task::Poll; + +use std::io; + +pub struct AdaptorFuture { + pub inner: F, +} + +impl Future for AdaptorFuture +where + F: Future, +{ + type Output = Result; + + fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + panic!() + } +} + +pub struct HyperFuture +where + B: ToString, +{ + inner: B, +} + +impl Future for HyperFuture +where + B: ToString, +{ + type Output = Result<(), io::Error>; + + fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + panic!() + } +} diff --git a/examples/lifetime_issue/src/main.rs b/examples/lifetime_issue/src/main.rs new file mode 100644 index 0000000..665b7ab --- /dev/null +++ b/examples/lifetime_issue/src/main.rs @@ -0,0 +1,14 @@ +use rio_rt::runitime as rio; + +mod future; +mod services; + +use crate::future::AdaptorFuture; +use crate::services::{HyperService, Service}; + +fn main() { + let service = HyperService::new("".to_string()); + rio::block_on(async move { + service.call("".to_string()); + }) +} diff --git a/examples/lifetime_issue/src/services.rs b/examples/lifetime_issue/src/services.rs new file mode 100644 index 0000000..ff7872c --- /dev/null +++ b/examples/lifetime_issue/src/services.rs @@ -0,0 +1,37 @@ +use crate::future::HyperFuture; +use crate::AdaptorFuture; +use std::future::Future; + +use std::fmt::Display; +use std::io; + +pub trait Service { + type Response; + + type Future: Future; + + fn call(&self, req: R) -> Self::Future; +} + +pub struct HyperService { + request_service: S, +} + +impl HyperService { + pub fn new(request_service: S) -> Self { + HyperService { request_service } + } +} + +impl Service for HyperService +where + S: ToString, +{ + type Response = Result<(), io::Error>; + + type Future = HyperFuture; + + fn call(&self, _: R) -> Self::Future { + panic!() + } +}