Skip to content

Commit 873a1b7

Browse files
committed
Add cfg(feature=alloc) guards
This allows us to compile capnproto in no-alloc environments.
1 parent 5414689 commit 873a1b7

29 files changed

+302
-32
lines changed

capnp/src/any_pointer.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121

2222
//! Untyped pointer that can be cast to any struct, list, or capability type.
2323
24-
use alloc::boxed::Box;
25-
use alloc::vec::Vec;
24+
#[cfg(feature = "alloc")]
25+
use alloc::{boxed::Box, vec::Vec};
2626

27+
#[cfg(feature = "alloc")]
2728
use crate::capability::FromClientHook;
29+
#[cfg(feature = "alloc")]
2830
use crate::private::capability::{ClientHook, PipelineHook, PipelineOp};
2931
use crate::private::layout::{PointerBuilder, PointerReader};
3032
use crate::traits::{FromPointerBuilder, FromPointerReader, SetPointerBuilder};
@@ -44,6 +46,7 @@ impl crate::introspect::Introspect for Owned {
4446
}
4547
}
4648

49+
#[cfg(feature = "alloc")]
4750
impl crate::traits::Pipelined for Owned {
4851
type Pipeline = Pipeline;
4952
}
@@ -73,12 +76,14 @@ impl<'a> Reader<'a> {
7376
FromPointerReader::get_from_pointer(&self.reader, None)
7477
}
7578

79+
#[cfg(feature = "alloc")]
7680
pub fn get_as_capability<T: FromClientHook>(&self) -> Result<T> {
7781
Ok(FromClientHook::new(self.reader.get_capability()?))
7882
}
7983

8084
//# Used by RPC system to implement pipelining. Applications
8185
//# generally shouldn't use this directly.
86+
#[cfg(feature = "alloc")]
8287
pub fn get_pipelined_cap(&self, ops: &[PipelineOp]) -> Result<Box<dyn ClientHook>> {
8388
let mut pointer = self.reader;
8489

@@ -117,6 +122,7 @@ impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
117122
}
118123
}
119124

125+
#[cfg(feature = "alloc")]
120126
impl<'a> crate::traits::Imbue<'a> for Reader<'a> {
121127
fn imbue(&mut self, cap_table: &'a crate::private::layout::CapTable) {
122128
self.reader
@@ -165,6 +171,7 @@ impl<'a> Builder<'a> {
165171
}
166172

167173
// XXX value should be a user client.
174+
#[cfg(feature = "alloc")]
168175
pub fn set_as_capability(&mut self, value: Box<dyn ClientHook>) {
169176
self.builder.set_capability(value);
170177
}
@@ -199,20 +206,23 @@ impl<'a> FromPointerBuilder<'a> for Builder<'a> {
199206
}
200207
}
201208

209+
#[cfg(feature = "alloc")]
202210
impl<'a> crate::traits::ImbueMut<'a> for Builder<'a> {
203211
fn imbue_mut(&mut self, cap_table: &'a mut crate::private::layout::CapTable) {
204212
self.builder
205213
.imbue(crate::private::layout::CapTableBuilder::Plain(cap_table));
206214
}
207215
}
208216

217+
#[cfg(feature = "alloc")]
209218
pub struct Pipeline {
210219
// XXX this should not be public
211220
pub hook: Box<dyn PipelineHook>,
212221

213222
ops: Vec<PipelineOp>,
214223
}
215224

225+
#[cfg(feature = "alloc")]
216226
impl Pipeline {
217227
pub fn new(hook: Box<dyn PipelineHook>) -> Self {
218228
Self {
@@ -245,24 +255,28 @@ impl Pipeline {
245255
}
246256
}
247257

258+
#[cfg(feature = "alloc")]
248259
impl crate::capability::FromTypelessPipeline for Pipeline {
249260
fn new(typeless: Pipeline) -> Self {
250261
typeless
251262
}
252263
}
253264

265+
#[cfg(feature = "alloc")]
254266
impl<'a> From<Reader<'a>> for crate::dynamic_value::Reader<'a> {
255267
fn from(a: Reader<'a>) -> crate::dynamic_value::Reader<'a> {
256268
crate::dynamic_value::Reader::AnyPointer(a)
257269
}
258270
}
259271

272+
#[cfg(feature = "alloc")]
260273
impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
261274
fn from(a: Builder<'a>) -> crate::dynamic_value::Builder<'a> {
262275
crate::dynamic_value::Builder::AnyPointer(a)
263276
}
264277
}
265278

279+
#[cfg(feature = "alloc")]
266280
#[test]
267281
fn init_clears_value() {
268282
let mut message = crate::message::Builder::new_default();

capnp/src/any_pointer_list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<'a> core::iter::IntoIterator for Reader<'a> {
189189
}
190190
}
191191

192+
#[cfg(feature = "alloc")]
192193
impl<'a> From<Reader<'a>> for crate::dynamic_value::Reader<'a> {
193194
fn from(t: Reader<'a>) -> crate::dynamic_value::Reader<'a> {
194195
crate::dynamic_value::Reader::List(crate::dynamic_list::Reader::new(
@@ -198,6 +199,7 @@ impl<'a> From<Reader<'a>> for crate::dynamic_value::Reader<'a> {
198199
}
199200
}
200201

202+
#[cfg(feature = "alloc")]
201203
impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
202204
fn from(t: Builder<'a>) -> crate::dynamic_value::Builder<'a> {
203205
crate::dynamic_value::Builder::List(crate::dynamic_list::Builder::new(

capnp/src/capability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! Hooks for for the RPC system.
2323
//!
2424
//! Roughly corresponds to capability.h in the C++ implementation.
25+
#![cfg(feature = "alloc")]
2526

2627
use alloc::boxed::Box;
2728
use core::future::Future;

capnp/src/capability_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// THE SOFTWARE.
2020

2121
//! List of capabilities.
22+
#![cfg(feature = "alloc")]
2223

2324
use alloc::boxed::Box;
2425
use core::marker::PhantomData;

capnp/src/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
8282
}
8383
}
8484

85+
#[cfg(feature = "alloc")]
8586
impl<'a> From<Reader<'a>> for crate::dynamic_value::Reader<'a> {
8687
fn from(d: Reader<'a>) -> crate::dynamic_value::Reader<'a> {
8788
crate::dynamic_value::Reader::Data(d)
8889
}
8990
}
9091

92+
#[cfg(feature = "alloc")]
9193
impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
9294
fn from(d: Builder<'a>) -> crate::dynamic_value::Builder<'a> {
9395
crate::dynamic_value::Builder::Data(d)

capnp/src/data_list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl<'a> ::core::iter::IntoIterator for Reader<'a> {
199199
}
200200
}
201201

202+
#[cfg(feature = "alloc")]
202203
impl<'a> From<Reader<'a>> for crate::dynamic_value::Reader<'a> {
203204
fn from(t: Reader<'a>) -> crate::dynamic_value::Reader<'a> {
204205
crate::dynamic_value::Reader::List(crate::dynamic_list::Reader {
@@ -208,6 +209,7 @@ impl<'a> From<Reader<'a>> for crate::dynamic_value::Reader<'a> {
208209
}
209210
}
210211

212+
#[cfg(feature = "alloc")]
211213
impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
212214
fn from(t: Builder<'a>) -> crate::dynamic_value::Builder<'a> {
213215
crate::dynamic_value::Builder::List(crate::dynamic_list::Builder {

capnp/src/dynamic_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Dynamically-typed lists.
22
3+
#![cfg(feature = "alloc")]
34
use crate::dynamic_value;
45
use crate::introspect::{Type, TypeVariant};
56
use crate::private::layout::{self, PrimitiveElement};

capnp/src/dynamic_struct.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Dynamically-typed structs.
22
3+
#![cfg(feature = "alloc")]
34
use crate::introspect::TypeVariant;
45
use crate::private::layout;
56
use crate::schema::{Field, StructSchema};

capnp/src/dynamic_value.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Dynamically typed values.
22
3+
#![cfg(feature = "alloc")]
34
use crate::introspect::{self, TypeVariant};
45
use crate::schema_capnp::value;
56
use crate::Result;

capnp/src/enum_list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl<'a, T: TryFrom<u16, Error = NotInSchema>> ::core::iter::IntoIterator for Re
214214
}
215215
}
216216

217+
#[cfg(feature = "alloc")]
217218
impl<'a, T: TryFrom<u16, Error = NotInSchema> + crate::introspect::Introspect> From<Reader<'a, T>>
218219
for crate::dynamic_value::Reader<'a>
219220
{
@@ -225,6 +226,7 @@ impl<'a, T: TryFrom<u16, Error = NotInSchema> + crate::introspect::Introspect> F
225226
}
226227
}
227228

229+
#[cfg(feature = "alloc")]
228230
impl<'a, T: TryFrom<u16, Error = NotInSchema> + crate::introspect::Introspect> From<Builder<'a, T>>
229231
for crate::dynamic_value::Builder<'a>
230232
{

0 commit comments

Comments
 (0)