Skip to content

Commit

Permalink
Move the thing that prevents no_std into rpc
Browse files Browse the repository at this point in the history
So, [currently][1], `async` fns/closures prevent crates from building in
a no_std environment. Since the only occurrence is this single `send`
method, I've moved it to the rpc crate.

[1]: rust-lang/rust#56974
  • Loading branch information
killercup committed Feb 11, 2020
1 parent 21ca13c commit e6499e2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions capnp-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ mod sender_queue;
mod split;
mod task_set;
pub mod twoparty;
mod send_ext;

pub trait OutgoingMessage {
fn get_body<'a>(&'a mut self) -> ::capnp::Result<::capnp::any_pointer::Builder<'a>>;
Expand Down
1 change: 1 addition & 0 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::attach::Attach;
use crate::{broken, local, queued};
use crate::local::ResultsDoneHook;
use crate::task_set::TaskSet;
use crate::send_ext::SendExt;

pub type QuestionId = u32;
pub type AnswerId = QuestionId;
Expand Down
32 changes: 32 additions & 0 deletions capnp-rpc/src/send_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use capnp::capability::{FromTypelessPipeline, Promise, RemotePromise, Request, Response};
use capnp::traits::{Owned, Pipelined};
use core::marker::PhantomData;

pub trait SendExt<Results>
where
Results: Pipelined + for<'a> Owned<'a> + 'static + Unpin,
{
fn send(self) -> RemotePromise<Results>;
}

impl<Params, Results> SendExt<Results> for Request<Params, Results>
where
Results: Pipelined + for<'a> Owned<'a> + 'static + Unpin,
<Results as Pipelined>::Pipeline: FromTypelessPipeline,
{
fn send(self) -> RemotePromise<Results> {
let RemotePromise {
promise, pipeline, ..
} = self.hook.send();
let typed_promise = Promise::from_future(async move {
Ok(Response {
hook: promise.await?.hook,
marker: PhantomData,
})
});
RemotePromise {
promise: typed_promise,
pipeline: FromTypelessPipeline::new(pipeline),
}
}
}
4 changes: 0 additions & 4 deletions capnp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ pub mod any_pointer;
pub mod any_pointer_list;
pub mod capability;
pub mod capability_list;
// #[cfg(not(feature = "std"))]
mod capability_no_std;
// #[cfg(feature = "std")]
// mod capability_std;
pub mod constant;
pub mod data;
pub mod data_list;
Expand Down

0 comments on commit e6499e2

Please sign in to comment.