Skip to content

Commit

Permalink
Update rust generator for no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobsonchase committed May 22, 2019
1 parent ae472da commit e991490
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/idl_gen_rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class RustGenerator : public BaseGenerator {
"yield",

// other rust terms we should not use
"core",
"std",
"usize",
"isize",
Expand Down Expand Up @@ -1477,7 +1478,7 @@ class RustGenerator : public BaseGenerator {
code_ += "";
code_ += " #[inline]";
code_ += " pub fn key_compare_with_value(&self, val: {{KEY_TYPE}}) -> "
" ::std::cmp::Ordering {";
" ::core::cmp::Ordering {";
code_ += " let key = self.{{FIELD_NAME}}();";
code_ += " key.cmp(&val)";
code_ += " }";
Expand Down Expand Up @@ -1648,7 +1649,7 @@ class RustGenerator : public BaseGenerator {
code_ += " #[inline]";
code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {";
code_ += " let src = unsafe {";
code_ += " ::std::slice::from_raw_parts("
code_ += " ::core::slice::from_raw_parts("
"self as *const {{STRUCT_NAME}} as *const u8, Self::size())";
code_ += " };";
code_ += " dst.copy_from_slice(src);";
Expand All @@ -1660,7 +1661,7 @@ class RustGenerator : public BaseGenerator {
code_ += " #[inline]";
code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {";
code_ += " let src = unsafe {";
code_ += " ::std::slice::from_raw_parts("
code_ += " ::core::slice::from_raw_parts("
"*self as *const {{STRUCT_NAME}} as *const u8, Self::size())";
code_ += " };";
code_ += " dst.copy_from_slice(src);";
Expand Down Expand Up @@ -1746,8 +1747,8 @@ class RustGenerator : public BaseGenerator {
void GenNamespaceImports(const int white_spaces) {
std::string indent = std::string(white_spaces, ' ');
code_ += "";
code_ += indent + "use std::mem;";
code_ += indent + "use std::cmp::Ordering;";
code_ += indent + "use core::mem;";
code_ += indent + "use core::cmp::Ordering;";
code_ += "";
code_ += indent + "extern crate flatbuffers;";
code_ += indent + "use self::flatbuffers::EndianScalar;";
Expand Down

0 comments on commit e991490

Please sign in to comment.