mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 12:54:12 +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::*;
|
||||
// struct ArrayStruct, aligned to 8
|
||||
@@ -13,8 +17,8 @@ impl Default for ArrayStruct {
|
||||
Self([0; 160])
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for ArrayStruct {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for ArrayStruct {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.debug_struct("ArrayStruct")
|
||||
.field("a", &self.a())
|
||||
.field("b", &self.b())
|
||||
@@ -47,7 +51,7 @@ impl<'b> flatbuffers::Push for ArrayStruct {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
@@ -58,7 +62,7 @@ impl<'b> flatbuffers::Push for &'b ArrayStruct {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
@@ -158,7 +162,7 @@ impl<'a> ArrayStruct {
|
||||
|
||||
pub fn set_d(&mut self, x: &[NestedStruct; 2]) {
|
||||
unsafe {
|
||||
std::ptr::copy(
|
||||
core::ptr::copy(
|
||||
x.as_ptr() as *const u8,
|
||||
self.0.as_mut_ptr().add(72),
|
||||
64,
|
||||
|
||||
@@ -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 ArrayTableOffset {}
|
||||
@@ -103,8 +107,8 @@ impl<'a: 'b, 'b> ArrayTableBuilder<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ArrayTable<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for ArrayTable<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("ArrayTable");
|
||||
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 NestedStruct, aligned to 8
|
||||
@@ -13,8 +17,8 @@ impl Default for NestedStruct {
|
||||
Self([0; 32])
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for NestedStruct {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for NestedStruct {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.debug_struct("NestedStruct")
|
||||
.field("a", &self.a())
|
||||
.field("b", &self.b())
|
||||
@@ -45,7 +49,7 @@ impl<'b> flatbuffers::Push for NestedStruct {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
@@ -56,7 +60,7 @@ impl<'b> flatbuffers::Push for &'b NestedStruct {
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size())
|
||||
::core::slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
@@ -129,7 +133,7 @@ impl<'a> NestedStruct {
|
||||
|
||||
pub fn set_c(&mut self, x: &[TestEnum; 2]) {
|
||||
unsafe {
|
||||
std::ptr::copy(
|
||||
core::ptr::copy(
|
||||
x.as_ptr() as *const u8,
|
||||
self.0.as_mut_ptr().add(9),
|
||||
2,
|
||||
|
||||
@@ -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 TestEnum {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for TestEnum {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for TestEnum {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
f.write_str(name)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user