Skip to content

Commit

Permalink
Merge pull request #13 from vincenzopalazzo/macros/example
Browse files Browse the repository at this point in the history
add new example to reprodue a rust issue
  • Loading branch information
vincenzopalazzo authored Dec 19, 2022
2 parents 729f794 + d6f1816 commit a970fc3
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
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!()
}
}

0 comments on commit a970fc3

Please sign in to comment.