Skip to content

Commit e6499e2

Browse files
author
Pascal Hertleif
committed
Move the thing that prevents no_std into rpc
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
1 parent 21ca13c commit e6499e2

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

capnp-rpc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ mod sender_queue;
112112
mod split;
113113
mod task_set;
114114
pub mod twoparty;
115+
mod send_ext;
115116

116117
pub trait OutgoingMessage {
117118
fn get_body<'a>(&'a mut self) -> ::capnp::Result<::capnp::any_pointer::Builder<'a>>;

capnp-rpc/src/rpc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use crate::attach::Attach;
4444
use crate::{broken, local, queued};
4545
use crate::local::ResultsDoneHook;
4646
use crate::task_set::TaskSet;
47+
use crate::send_ext::SendExt;
4748

4849
pub type QuestionId = u32;
4950
pub type AnswerId = QuestionId;

capnp-rpc/src/send_ext.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use capnp::capability::{FromTypelessPipeline, Promise, RemotePromise, Request, Response};
2+
use capnp::traits::{Owned, Pipelined};
3+
use core::marker::PhantomData;
4+
5+
pub trait SendExt<Results>
6+
where
7+
Results: Pipelined + for<'a> Owned<'a> + 'static + Unpin,
8+
{
9+
fn send(self) -> RemotePromise<Results>;
10+
}
11+
12+
impl<Params, Results> SendExt<Results> for Request<Params, Results>
13+
where
14+
Results: Pipelined + for<'a> Owned<'a> + 'static + Unpin,
15+
<Results as Pipelined>::Pipeline: FromTypelessPipeline,
16+
{
17+
fn send(self) -> RemotePromise<Results> {
18+
let RemotePromise {
19+
promise, pipeline, ..
20+
} = self.hook.send();
21+
let typed_promise = Promise::from_future(async move {
22+
Ok(Response {
23+
hook: promise.await?.hook,
24+
marker: PhantomData,
25+
})
26+
});
27+
RemotePromise {
28+
promise: typed_promise,
29+
pipeline: FromTypelessPipeline::new(pipeline),
30+
}
31+
}
32+
}

capnp/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ pub mod any_pointer;
3939
pub mod any_pointer_list;
4040
pub mod capability;
4141
pub mod capability_list;
42-
// #[cfg(not(feature = "std"))]
43-
mod capability_no_std;
44-
// #[cfg(feature = "std")]
45-
// mod capability_std;
4642
pub mod constant;
4743
pub mod data;
4844
pub mod data_list;

0 commit comments

Comments
 (0)