mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-30 19:00:02 +00:00
Make flatc generate Rust files not requiring std (#7273)
* Set an explicit 2018 edition for Rust tests * Replace all `std` usage with `core` and `alloc` in Rust code generator * Update the generated files * Make Rust tests actually use no_std when the corresponding feature is enabled
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use std::mem;
|
||||
use std::cmp::Ordering;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
extern crate serde;
|
||||
use self::serde::ser::{Serialize, Serializer, SerializeStruct};
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
@@ -15,8 +19,8 @@ impl Default for Ability {
|
||||
Self([0; 8])
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for Ability {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for Ability {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.debug_struct("Ability")
|
||||
.field("id", &self.id())
|
||||
.field("distance", &self.distance())
|
||||
@@ -45,7 +49,7 @@ impl<'b> flatbuffers::Push for Ability {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(self as *const Ability as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
@@ -56,7 +60,7 @@ impl<'b> flatbuffers::Push for &'b Ability {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
@@ -129,7 +133,7 @@ impl<'a> Ability {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn key_compare_with_value(&self, val: u32) -> ::std::cmp::Ordering {
|
||||
pub fn key_compare_with_value(&self, val: u32) -> ::core::cmp::Ordering {
|
||||
let key = self.id();
|
||||
key.cmp(&val)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user