Skip to content

Commit e1ca2cc

Browse files
Add no_std feature
1 parent e8f8d22 commit e1ca2cc

24 files changed

+221
-119
lines changed

capnp/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ path = "src/lib.rs"
2020

2121
[dependencies]
2222
quickcheck = { version = "0.2", optional = true }
23+
core_io = { version = "0.1.20190701", features = [ "alloc", "collections" ], optional = true }
2324

2425
[dev-dependencies]
2526
quickcheck = "0.2"
2627

2728
[features]
29+
no_std = ["core_io"]
2830
rpc = ["futures"]
2931
rpc_try = []
32+
default = []
3033

3134
[dependencies.futures]
3235
version = "0.1"

capnp/src/any_pointer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
//! Dynamically typed value.
2323
24+
#[cfg(feature = "no_std")]
25+
use crate::io::prelude::*;
26+
2427
use crate::capability::FromClientHook;
2528
use crate::private::capability::{ClientHook, PipelineHook, PipelineOp};
2629
use crate::private::layout::{PointerReader, PointerBuilder};

capnp/src/any_pointer_list.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//! Note: this cannot be used for a list of structs, since such lists are not encoded
2424
//! as pointer lists.
2525
26+
use core;
2627
use crate::traits::{FromPointerReader, FromPointerBuilder, ListIter, IndexMove};
2728
use crate::private::layout::{ListReader, ListBuilder, PointerReader, PointerBuilder, Pointer};
2829
use crate::Result;
@@ -124,7 +125,7 @@ impl <'a> crate::traits::SetPointerBuilder<Builder<'a>> for Reader<'a> {
124125
}
125126
}
126127

127-
impl <'a> ::std::iter::IntoIterator for Reader<'a> {
128+
impl <'a> core::iter::IntoIterator for Reader<'a> {
128129
type Item = Result<crate::any_pointer::Reader<'a>>;
129130
type IntoIter = ListIter<Reader<'a>, Self::Item>;
130131

capnp/src/capability.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
//!
2424
//! Roughly corresponds to capability.h in the C++ implementation.
2525
26+
#[cfg(feature = "no_std")]
27+
use crate::io::prelude::*;
28+
use core::marker::PhantomData;
29+
2630
use crate::{any_pointer, Error, MessageSize};
2731
use crate::traits::{Pipelined, Owned};
2832
use crate::private::capability::{ClientHook, ParamsHook, RequestHook, ResponseHook, ResultsHook};
@@ -32,8 +36,6 @@ use futures::Future;
3236
#[cfg(feature = "rpc_try")]
3337
use std::ops::Try;
3438

35-
use std::marker::PhantomData;
36-
3739
/// A computation that might eventually resolve to a value of type `T` or to an error
3840
/// of type `E`. Dropping the promise cancels the computation.
3941
#[must_use = "futures do nothing unless polled"]

capnp/src/capability_list.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
//! List of capabilities.
2222
23-
use std::marker::PhantomData;
23+
#[cfg(feature = "no_std")]
24+
use crate::io::prelude::*;
25+
use core::{self, marker::PhantomData};
2426

2527
use crate::capability::{FromClientHook};
2628
use crate::private::capability::ClientHook;
@@ -152,7 +154,7 @@ impl <'a, T> crate::traits::SetPointerBuilder<Builder<'a, T>> for Reader<'a, T>
152154
}
153155
}
154156

155-
impl <'a, T> ::std::iter::IntoIterator for Reader<'a, T>
157+
impl <'a, T> core::iter::IntoIterator for Reader<'a, T>
156158
where T: FromClientHook
157159
{
158160
type Item = Result<T>;

capnp/src/constant.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
//! `constant::Reader` does not do bounds-checking, so it is unsafe to
2424
//! manually construct one of these.
2525
26-
use std::marker::PhantomData;
27-
26+
use core::marker::PhantomData;
2827
use crate::any_pointer;
2928
use crate::private::layout::PointerReader;
3029
use crate::traits::Owned;

capnp/src/data.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
//! Sequence of bytes.
2323
24+
use core;
2425
use crate::private::layout::{PointerBuilder, PointerReader};
2526
use crate::Result;
2627

@@ -35,7 +36,7 @@ impl<'a> crate::traits::Owned<'a> for Owned {
3536
pub type Reader<'a> = &'a [u8];
3637

3738
pub fn new_reader<'a>(p : *const u8, len : u32) -> Reader<'a> {
38-
unsafe { ::std::slice::from_raw_parts(p, len as usize) }
39+
unsafe { core::slice::from_raw_parts(p, len as usize) }
3940
}
4041

4142
impl <'a> crate::traits::FromPointerReader<'a> for Reader<'a> {
@@ -47,7 +48,7 @@ impl <'a> crate::traits::FromPointerReader<'a> for Reader<'a> {
4748
pub type Builder<'a> = &'a mut [u8];
4849

4950
pub fn new_builder<'a>(p : *mut u8, len : u32) -> Builder<'a> {
50-
unsafe { ::std::slice::from_raw_parts_mut(p, len as usize) }
51+
unsafe { core::slice::from_raw_parts_mut(p, len as usize) }
5152
}
5253

5354
impl <'a> crate::traits::FromPointerBuilder<'a> for Builder<'a> {

capnp/src/data_list.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
//! List of sequences of bytes.
2323
24+
use core;
2425
use crate::traits::{FromPointerReader, FromPointerBuilder, IndexMove, ListIter};
2526
use crate::private::layout::*;
2627
use crate::Result;
@@ -133,7 +134,7 @@ impl <'a> crate::traits::SetPointerBuilder<Builder<'a>> for Reader<'a> {
133134
}
134135
}
135136

136-
impl <'a> ::std::iter::IntoIterator for Reader<'a> {
137+
impl <'a> core::iter::IntoIterator for Reader<'a> {
137138
type Item = Result<crate::data::Reader<'a>>;
138139
type IntoIter = ListIter<Reader<'a>, Self::Item>;
139140

capnp/src/enum_list.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222
//! List of enums.
2323
24+
use core::{self, marker::PhantomData};
25+
2426
use crate::traits::{FromPointerReader, FromPointerBuilder,
2527
ToU16, FromU16, ListIter, IndexMove};
2628
use crate::private::layout::{ListReader, ListBuilder, PointerReader, PointerBuilder,
2729
TwoBytes, PrimitiveElement};
2830
use crate::{NotInSchema, Result};
2931

30-
use std::marker::PhantomData;
31-
3232
#[derive(Clone, Copy)]
3333
pub struct Owned<T> {
3434
marker: PhantomData<T>,
@@ -52,7 +52,7 @@ impl <'a, T: FromU16> Reader<'a, T> {
5252

5353
pub fn len(&self) -> u32 { self.reader.len() }
5454

55-
pub fn iter(self) -> ListIter<Reader<'a, T>, ::std::result::Result<T, NotInSchema>>{
55+
pub fn iter(self) -> ListIter<Reader<'a, T>, core::result::Result<T, NotInSchema>>{
5656
let l = self.len();
5757
ListIter::new(self, l)
5858
}
@@ -65,14 +65,14 @@ impl <'a, T : FromU16> FromPointerReader<'a> for Reader<'a, T> {
6565
}
6666
}
6767

68-
impl <'a, T: FromU16> IndexMove<u32, ::std::result::Result<T, NotInSchema>> for Reader<'a, T>{
69-
fn index_move(&self, index: u32) -> ::std::result::Result<T, NotInSchema> {
68+
impl <'a, T: FromU16> IndexMove<u32, core::result::Result<T, NotInSchema>> for Reader<'a, T>{
69+
fn index_move(&self, index: u32) -> core::result::Result<T, NotInSchema> {
7070
self.get(index)
7171
}
7272
}
7373

7474
impl <'a, T : FromU16> Reader<'a, T> {
75-
pub fn get(&self, index: u32) -> ::std::result::Result<T, NotInSchema> {
75+
pub fn get(&self, index: u32) -> core::result::Result<T, NotInSchema> {
7676
assert!(index < self.len());
7777
let result: u16 = PrimitiveElement::get(&self.reader, index);
7878
FromU16::from_u16(result)
@@ -119,7 +119,7 @@ impl <'a, T : FromU16> FromPointerBuilder<'a> for Builder<'a, T> {
119119
}
120120

121121
impl <'a, T : ToU16 + FromU16> Builder<'a, T> {
122-
pub fn get(&self, index: u32) -> ::std::result::Result<T, NotInSchema> {
122+
pub fn get(&self, index: u32) -> core::result::Result<T, NotInSchema> {
123123
assert!(index < self.len());
124124
let result: u16 = PrimitiveElement::get_from_builder(&self.builder, index);
125125
FromU16::from_u16(result)
@@ -138,8 +138,8 @@ impl <'a, T> crate::traits::SetPointerBuilder<Builder<'a, T>> for Reader<'a, T>
138138
}
139139
}
140140

141-
impl <'a, T: FromU16> ::std::iter::IntoIterator for Reader<'a, T> {
142-
type Item = ::std::result::Result<T, NotInSchema>;
141+
impl <'a, T: FromU16> core::iter::IntoIterator for Reader<'a, T> {
142+
type Item = core::result::Result<T, NotInSchema>;
143143
type IntoIter = ListIter<Reader<'a, T>, Self::Item>;
144144

145145
fn into_iter(self) -> Self::IntoIter {

0 commit comments

Comments
 (0)