mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 14:04:13 +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.")]
|
||||
@@ -46,8 +50,8 @@ impl Any {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for Any {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for Any {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
f.write_str(name)
|
||||
} else {
|
||||
@@ -135,7 +139,7 @@ impl AnyT {
|
||||
/// If the union variant matches, return the owned MonsterT, setting the union to NONE.
|
||||
pub fn take_monster(&mut self) -> Option<Box<MonsterT>> {
|
||||
if let Self::Monster(_) = self {
|
||||
let v = std::mem::replace(self, Self::NONE);
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::Monster(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
@@ -156,7 +160,7 @@ impl AnyT {
|
||||
/// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE.
|
||||
pub fn take_test_simple_table_with_enum(&mut self) -> Option<Box<TestSimpleTableWithEnumT>> {
|
||||
if let Self::TestSimpleTableWithEnum(_) = self {
|
||||
let v = std::mem::replace(self, Self::NONE);
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::TestSimpleTableWithEnum(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
@@ -177,7 +181,7 @@ impl AnyT {
|
||||
/// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE.
|
||||
pub fn take_my_game_example_2_monster(&mut self) -> Option<Box<super::example_2::MonsterT>> {
|
||||
if let Self::MyGameExample2Monster(_) = self {
|
||||
let v = std::mem::replace(self, Self::NONE);
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::MyGameExample2Monster(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user