-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from vincenzopalazzo/macros/example
add new example to reprodue a rust issue
- Loading branch information
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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" } |
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
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!() | ||
} | ||
} |
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
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()); | ||
}) | ||
} |
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
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!() | ||
} | ||
} |