Skip to content

Add no_std feature #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions capnp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ path = "src/lib.rs"

[dependencies]
quickcheck = { version = "0.2", optional = true }
core_io = { version = "0.1.20190701", features = [ "alloc", "collections" ], optional = true }

[dev-dependencies]
quickcheck = "0.2"

[features]
no_std = ["core_io"]
rpc = ["futures"]
rpc_try = []
default = []

[dependencies.futures]
version = "0.1"
Expand Down
3 changes: 3 additions & 0 deletions capnp/src/any_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

//! Dynamically typed value.

#[cfg(feature = "no_std")]
use crate::io::prelude::*;

use crate::capability::FromClientHook;
use crate::private::capability::{ClientHook, PipelineHook, PipelineOp};
use crate::private::layout::{PointerReader, PointerBuilder};
Expand Down
3 changes: 2 additions & 1 deletion capnp/src/any_pointer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//! Note: this cannot be used for a list of structs, since such lists are not encoded
//! as pointer lists.

use core;
use crate::traits::{FromPointerReader, FromPointerBuilder, ListIter, IndexMove};
use crate::private::layout::{ListReader, ListBuilder, PointerReader, PointerBuilder, Pointer};
use crate::Result;
Expand Down Expand Up @@ -124,7 +125,7 @@ impl <'a> crate::traits::SetPointerBuilder<Builder<'a>> for Reader<'a> {
}
}

impl <'a> ::std::iter::IntoIterator for Reader<'a> {
impl <'a> core::iter::IntoIterator for Reader<'a> {
type Item = Result<crate::any_pointer::Reader<'a>>;
type IntoIter = ListIter<Reader<'a>, Self::Item>;

Expand Down
6 changes: 4 additions & 2 deletions capnp/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
//!
//! Roughly corresponds to capability.h in the C++ implementation.

#[cfg(feature = "no_std")]
use crate::io::prelude::*;
use core::marker::PhantomData;

use crate::{any_pointer, Error, MessageSize};
use crate::traits::{Pipelined, Owned};
use crate::private::capability::{ClientHook, ParamsHook, RequestHook, ResponseHook, ResultsHook};
Expand All @@ -32,8 +36,6 @@ use futures::Future;
#[cfg(feature = "rpc_try")]
use std::ops::Try;

use std::marker::PhantomData;

/// A computation that might eventually resolve to a value of type `T` or to an error
/// of type `E`. Dropping the promise cancels the computation.
#[must_use = "futures do nothing unless polled"]
Expand Down
6 changes: 4 additions & 2 deletions capnp/src/capability_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

//! List of capabilities.

use std::marker::PhantomData;
#[cfg(feature = "no_std")]
use crate::io::prelude::*;
use core::{self, marker::PhantomData};

use crate::capability::{FromClientHook};
use crate::private::capability::ClientHook;
Expand Down Expand Up @@ -152,7 +154,7 @@ impl <'a, T> crate::traits::SetPointerBuilder<Builder<'a, T>> for Reader<'a, T>
}
}

impl <'a, T> ::std::iter::IntoIterator for Reader<'a, T>
impl <'a, T> core::iter::IntoIterator for Reader<'a, T>
where T: FromClientHook
{
type Item = Result<T>;
Expand Down
3 changes: 1 addition & 2 deletions capnp/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
//! `constant::Reader` does not do bounds-checking, so it is unsafe to
//! manually construct one of these.

use std::marker::PhantomData;

use core::marker::PhantomData;
use crate::any_pointer;
use crate::private::layout::PointerReader;
use crate::traits::Owned;
Expand Down
5 changes: 3 additions & 2 deletions capnp/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

//! Sequence of bytes.

use core;
use crate::private::layout::{PointerBuilder, PointerReader};
use crate::Result;

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

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

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

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

impl <'a> crate::traits::FromPointerBuilder<'a> for Builder<'a> {
Expand Down
3 changes: 2 additions & 1 deletion capnp/src/data_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

//! List of sequences of bytes.

use core;
use crate::traits::{FromPointerReader, FromPointerBuilder, IndexMove, ListIter};
use crate::private::layout::*;
use crate::Result;
Expand Down Expand Up @@ -133,7 +134,7 @@ impl <'a> crate::traits::SetPointerBuilder<Builder<'a>> for Reader<'a> {
}
}

impl <'a> ::std::iter::IntoIterator for Reader<'a> {
impl <'a> core::iter::IntoIterator for Reader<'a> {
type Item = Result<crate::data::Reader<'a>>;
type IntoIter = ListIter<Reader<'a>, Self::Item>;

Expand Down
18 changes: 9 additions & 9 deletions capnp/src/enum_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

//! List of enums.

use core::{self, marker::PhantomData};

use crate::traits::{FromPointerReader, FromPointerBuilder,
ToU16, FromU16, ListIter, IndexMove};
use crate::private::layout::{ListReader, ListBuilder, PointerReader, PointerBuilder,
TwoBytes, PrimitiveElement};
use crate::{NotInSchema, Result};

use std::marker::PhantomData;

#[derive(Clone, Copy)]
pub struct Owned<T> {
marker: PhantomData<T>,
Expand All @@ -52,7 +52,7 @@ impl <'a, T: FromU16> Reader<'a, T> {

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

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

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

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

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

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

fn into_iter(self) -> Self::IntoIter {
Expand Down
Loading