mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 19:48:52 +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;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
@@ -34,8 +38,8 @@ impl FromInclude {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for FromInclude {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for FromInclude {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
f.write_str(name)
|
||||
} else {
|
||||
|
||||
@@ -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;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum TableBOffset {}
|
||||
@@ -103,8 +107,8 @@ impl<'a: 'b, 'b> TableBBuilder<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TableB<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for TableB<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("TableB");
|
||||
ds.field("a", &self.a());
|
||||
ds.finish()
|
||||
|
||||
@@ -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;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
// struct Unused, aligned to 4
|
||||
@@ -13,8 +17,8 @@ impl Default for Unused {
|
||||
Self([0; 4])
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for Unused {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for Unused {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.debug_struct("Unused")
|
||||
.field("a", &self.a())
|
||||
.finish()
|
||||
@@ -42,7 +46,7 @@ impl<'b> flatbuffers::Push for Unused {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
@@ -53,7 +57,7 @@ impl<'b> flatbuffers::Push for &'b Unused {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum TableAOffset {}
|
||||
@@ -103,8 +107,8 @@ impl<'a: 'b, 'b> TableABuilder<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TableA<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for TableA<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("TableA");
|
||||
ds.field("b", &self.b());
|
||||
ds.finish()
|
||||
|
||||
Reference in New Issue
Block a user