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:
Bogdan Opanchuk
2022-04-26 18:40:03 -07:00
committed by GitHub
parent 9917a168cd
commit 750dde7669
88 changed files with 799 additions and 430 deletions

View File

@@ -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.")]
@@ -42,8 +46,8 @@ impl ABC {
}
}
}
impl std::fmt::Debug for ABC {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Debug for ABC {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
if let Some(name) = self.variant_name() {
f.write_str(name)
} else {

View File

@@ -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 KeywordsInTableOffset {}
@@ -146,8 +150,8 @@ impl<'a: 'b, 'b> KeywordsInTableBuilder<'a, 'b> {
}
}
impl std::fmt::Debug for KeywordsInTable<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Debug for KeywordsInTable<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut ds = f.debug_struct("KeywordsInTable");
ds.field("is", &self.is());
ds.field("private", &self.private());

View File

@@ -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.")]
@@ -42,8 +46,8 @@ impl KeywordsInUnion {
}
}
}
impl std::fmt::Debug for KeywordsInUnion {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Debug for KeywordsInUnion {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
if let Some(name) = self.variant_name() {
f.write_str(name)
} else {
@@ -128,7 +132,7 @@ impl KeywordsInUnionT {
/// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE.
pub fn take_static_(&mut self) -> Option<Box<KeywordsInTableT>> {
if let Self::Static_(_) = self {
let v = std::mem::replace(self, Self::NONE);
let v = core::mem::replace(self, Self::NONE);
if let Self::Static_(w) = v {
Some(w)
} else {
@@ -149,7 +153,7 @@ impl KeywordsInUnionT {
/// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE.
pub fn take_internal(&mut self) -> Option<Box<KeywordsInTableT>> {
if let Self::Internal(_) = self {
let v = std::mem::replace(self, Self::NONE);
let v = core::mem::replace(self, Self::NONE);
if let Self::Internal(w) = v {
Some(w)
} else {

View File

@@ -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 public {
}
}
}
impl std::fmt::Debug for public {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Debug for public {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
if let Some(name) = self.variant_name() {
f.write_str(name)
} else {