Skip to content

Commit

Permalink
Support alloc-only no_std platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobsonchase committed May 22, 2019
1 parent b04736f commit ae472da
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 17 deletions.
13 changes: 8 additions & 5 deletions rust/flatbuffers/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

extern crate smallvec;

use std::cmp::max;
use std::marker::PhantomData;
use std::ptr::write_bytes;
use std::slice::from_raw_parts;
use alloc::vec;
use alloc::vec::Vec;

use core::cmp::max;
use core::marker::PhantomData;
use core::ptr::write_bytes;
use core::slice::from_raw_parts;

use endian_scalar::{read_scalar, emplace_scalar};
use primitives::*;
Expand Down Expand Up @@ -605,7 +608,7 @@ impl<'fbb> FlatBufferBuilder<'fbb> {
fn assert_nested(&self, fn_name: &'static str) {
// we don't assert that self.field_locs.len() >0 because the vtable
// could be empty (e.g. for empty tables, or for all-default values).
debug_assert!(self.nested, format!("incorrect FlatBufferBuilder usage: {} must be called while in a nested state", fn_name));
debug_assert!(self.nested, "incorrect FlatBufferBuilder usage: {} must be called while in a nested state", fn_name);
}
#[inline]
fn assert_not_nested(&self, msg: &'static str) {
Expand Down
2 changes: 1 addition & 1 deletion rust/flatbuffers/src/endian_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

use std::mem::size_of;
use core::mem::size_of;

/// Trait for values that must be stored in little-endian byte order, but
/// might be represented in memory as big-endian. Every type that implements
Expand Down
2 changes: 1 addition & 1 deletion rust/flatbuffers/src/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

use std::marker::PhantomData;
use core::marker::PhantomData;

/// Follow is a trait that allows us to access FlatBuffers in a declarative,
/// type safe, and fast way. They compile down to almost no code (after
Expand Down
4 changes: 4 additions & 0 deletions rust/flatbuffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
//! At this time, to generate Rust code, you will need the latest `master` version of `flatc`, available from here: https://github.com/google/flatbuffers
//! (On OSX, you can install FlatBuffers from `HEAD` with the Homebrew package manager.)
#![no_std]

extern crate alloc;

mod builder;
mod endian_scalar;
mod follow;
Expand Down
6 changes: 3 additions & 3 deletions rust/flatbuffers/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

use std::marker::PhantomData;
use std::mem::size_of;
use std::ops::Deref;
use core::marker::PhantomData;
use core::mem::size_of;
use core::ops::Deref;

use endian_scalar::{emplace_scalar, read_scalar, read_scalar_at};
use follow::Follow;
Expand Down
4 changes: 2 additions & 2 deletions rust/flatbuffers/src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

use std::cmp::max;
use std::mem::{align_of, size_of};
use core::cmp::max;
use core::mem::{align_of, size_of};

use endian_scalar::emplace_scalar;

Expand Down
8 changes: 4 additions & 4 deletions rust/flatbuffers/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

use std::marker::PhantomData;
use std::mem::size_of;
use std::slice::from_raw_parts;
use std::str::from_utf8_unchecked;
use core::marker::PhantomData;
use core::mem::size_of;
use core::slice::from_raw_parts;
use core::str::from_utf8_unchecked;

#[cfg(target_endian = "little")]
use endian_scalar::EndianScalar;
Expand Down
2 changes: 1 addition & 1 deletion rust/flatbuffers/src/vtable_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

use std::ptr::write_bytes;
use core::ptr::write_bytes;

use endian_scalar::{emplace_scalar, read_scalar};
use primitives::*;
Expand Down

0 comments on commit ae472da

Please sign in to comment.