Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new example to reprodue a rust issue #13

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ members = [
"io",
"lib",
"rt",
"examples/rio_triage_await"
"examples/rio_triage_await",
"examples/lifetime_issue",
]
7 changes: 7 additions & 0 deletions examples/lifetime_issue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "lifetime_issue"
version = "0.1.0"
edition = "2021"

[dependencies]
rio_rt = { path = "../../rt" }
39 changes: 39 additions & 0 deletions examples/lifetime_issue/src/future.rs
Original file line number Diff line number Diff line change
@@ -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<F> {
pub inner: F,
}

impl<F, T> Future for AdaptorFuture<F>
where
F: Future<Output = T>,
{
type Output = Result<T, io::Error>;

fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
panic!()
}
}

pub struct HyperFuture<B>
where
B: ToString,
{
inner: B,
}

impl<B> Future for HyperFuture<B>
where
B: ToString,
{
type Output = Result<(), io::Error>;

fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
panic!()
}
}
14 changes: 14 additions & 0 deletions examples/lifetime_issue/src/main.rs
Original file line number Diff line number Diff line change
@@ -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());
})
}
37 changes: 37 additions & 0 deletions examples/lifetime_issue/src/services.rs
Original file line number Diff line number Diff line change
@@ -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<R> {
type Response;

type Future: Future<Output = Self::Response>;

fn call(&self, req: R) -> Self::Future;
}

pub struct HyperService<S> {
request_service: S,
}

impl<S> HyperService<S> {
pub fn new(request_service: S) -> Self {
HyperService { request_service }
}
}

impl<S, R> Service<R> for HyperService<S>
where
S: ToString,
{
type Response = Result<(), io::Error>;

type Future = HyperFuture<String>;

fn call(&self, _: R) -> Self::Future {
panic!()
}
}