Skip to content

Commit d6f1816

Browse files
add new example to reprodue a rust issue
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 8f818b7 commit d6f1816

File tree

6 files changed

+106
-1
lines changed

6 files changed

+106
-1
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ members = [
44
"io",
55
"lib",
66
"rt",
7-
"examples/rio_triage_await"
7+
"examples/rio_triage_await",
8+
"examples/lifetime_issue",
89
]

examples/lifetime_issue/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "lifetime_issue"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rio_rt = { path = "../../rt" }

examples/lifetime_issue/src/future.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::future::Future;
2+
use std::pin::Pin;
3+
use std::task::Context;
4+
use std::task::Poll;
5+
6+
use std::io;
7+
8+
pub struct AdaptorFuture<F> {
9+
pub inner: F,
10+
}
11+
12+
impl<F, T> Future for AdaptorFuture<F>
13+
where
14+
F: Future<Output = T>,
15+
{
16+
type Output = Result<T, io::Error>;
17+
18+
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
19+
panic!()
20+
}
21+
}
22+
23+
pub struct HyperFuture<B>
24+
where
25+
B: ToString,
26+
{
27+
inner: B,
28+
}
29+
30+
impl<B> Future for HyperFuture<B>
31+
where
32+
B: ToString,
33+
{
34+
type Output = Result<(), io::Error>;
35+
36+
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
37+
panic!()
38+
}
39+
}

examples/lifetime_issue/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use rio_rt::runitime as rio;
2+
3+
mod future;
4+
mod services;
5+
6+
use crate::future::AdaptorFuture;
7+
use crate::services::{HyperService, Service};
8+
9+
fn main() {
10+
let service = HyperService::new("".to_string());
11+
rio::block_on(async move {
12+
service.call("".to_string());
13+
})
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use crate::future::HyperFuture;
2+
use crate::AdaptorFuture;
3+
use std::future::Future;
4+
5+
use std::fmt::Display;
6+
use std::io;
7+
8+
pub trait Service<R> {
9+
type Response;
10+
11+
type Future: Future<Output = Self::Response>;
12+
13+
fn call(&self, req: R) -> Self::Future;
14+
}
15+
16+
pub struct HyperService<S> {
17+
request_service: S,
18+
}
19+
20+
impl<S> HyperService<S> {
21+
pub fn new(request_service: S) -> Self {
22+
HyperService { request_service }
23+
}
24+
}
25+
26+
impl<S, R> Service<R> for HyperService<S>
27+
where
28+
S: ToString,
29+
{
30+
type Response = Result<(), io::Error>;
31+
32+
type Future = HyperFuture<String>;
33+
34+
fn call(&self, _: R) -> Self::Future {
35+
panic!()
36+
}
37+
}

0 commit comments

Comments
 (0)