diff --git a/conan/travis/build.sh b/conan/travis/build.sh index 069ced202f8..ede93ad9c6d 100755 --- a/conan/travis/build.sh +++ b/conan/travis/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e set -x diff --git a/conan/travis/install.sh b/conan/travis/install.sh index f4208d82643..c96c42b6603 100755 --- a/conan/travis/install.sh +++ b/conan/travis/install.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e set -x diff --git a/grpc/build_grpc.sh b/grpc/build_grpc.sh index 49c5a60f0eb..380f67400c8 100755 --- a/grpc/build_grpc.sh +++ b/grpc/build_grpc.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash grpc_1_39_0_githash=58602e20a3f3e48f24a4114c757099b25b947f7b diff --git a/grpc/examples/generate.sh b/grpc/examples/generate.sh index 39ca6620c3a..49f4be2629a 100755 --- a/grpc/examples/generate.sh +++ b/grpc/examples/generate.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/grpc/examples/go/format.sh b/grpc/examples/go/format.sh index a7ee9e3156a..3281ff7a08c 100644 --- a/grpc/examples/go/format.sh +++ b/grpc/examples/go/format.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/reflection/generate_code.sh b/reflection/generate_code.sh index 694baa2d74a..4b7d2f242c5 100755 --- a/reflection/generate_code.sh +++ b/reflection/generate_code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2016 Google Inc. All rights reserved. # diff --git a/rust/flatbuffers/Cargo.toml b/rust/flatbuffers/Cargo.toml index b3114bd7674..00e505bf839 100644 --- a/rust/flatbuffers/Cargo.toml +++ b/rust/flatbuffers/Cargo.toml @@ -14,4 +14,8 @@ rust = "1.51" [dependencies] smallvec = "1.6.1" bitflags = "1.2.1" -thiserror = "1.0.23" +thiserror = { version = "1.0.23", optional = true } + +[features] +default = ["std"] +std = ["thiserror"] diff --git a/rust/flatbuffers/src/array.rs b/rust/flatbuffers/src/array.rs index f00a56036a2..3765a5fcf40 100644 --- a/rust/flatbuffers/src/array.rs +++ b/rust/flatbuffers/src/array.rs @@ -17,9 +17,9 @@ use crate::follow::Follow; use crate::vector::VectorIter; use crate::EndianScalar; -use std::fmt::{Debug, Formatter, Result}; -use std::marker::PhantomData; -use std::mem::size_of; +use core::fmt::{Debug, Formatter, Result}; +use core::marker::PhantomData; +use core::mem::size_of; #[derive(Copy, Clone)] pub struct Array<'a, T: 'a, const N: usize>(&'a [u8], PhantomData); diff --git a/rust/flatbuffers/src/builder.rs b/rust/flatbuffers/src/builder.rs index 9309877116b..e931eff651e 100644 --- a/rust/flatbuffers/src/builder.rs +++ b/rust/flatbuffers/src/builder.rs @@ -16,11 +16,12 @@ extern crate smallvec; -use std::cmp::max; -use std::iter::{DoubleEndedIterator, ExactSizeIterator}; -use std::marker::PhantomData; -use std::ptr::write_bytes; -use std::slice::from_raw_parts; +use alloc::{vec, vec::Vec}; +use core::cmp::max; +use core::iter::{DoubleEndedIterator, ExactSizeIterator}; +use core::marker::PhantomData; +use core::ptr::write_bytes; +use core::slice::from_raw_parts; use crate::endian_scalar::{emplace_scalar, read_scalar_at}; use crate::primitives::*; diff --git a/rust/flatbuffers/src/endian_scalar.rs b/rust/flatbuffers/src/endian_scalar.rs index 7e8d8e3e442..5f50cf1f36e 100644 --- a/rust/flatbuffers/src/endian_scalar.rs +++ b/rust/flatbuffers/src/endian_scalar.rs @@ -15,7 +15,7 @@ */ #![allow(clippy::wrong_self_convention)] -use std::mem::size_of; +use core::mem::size_of; /// Trait for values that must be stored in little-endian byte order, but /// might be represented in memory as big-endian. Every type that implements diff --git a/rust/flatbuffers/src/follow.rs b/rust/flatbuffers/src/follow.rs index a09003d7d5d..d1d6483ae67 100644 --- a/rust/flatbuffers/src/follow.rs +++ b/rust/flatbuffers/src/follow.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::marker::PhantomData; +use core::marker::PhantomData; /// Follow is a trait that allows us to access FlatBuffers in a declarative, /// type safe, and fast way. They compile down to almost no code (after diff --git a/rust/flatbuffers/src/lib.rs b/rust/flatbuffers/src/lib.rs index 465e169062f..a3e3b4470be 100644 --- a/rust/flatbuffers/src/lib.rs +++ b/rust/flatbuffers/src/lib.rs @@ -28,6 +28,14 @@ //! At this time, to generate Rust code, you will need the latest `master` version of `flatc`, available from here: //! (On OSX, you can install FlatBuffers from `HEAD` with the Homebrew package manager.) +#![no_std] + +// Needed for thiserror +#[cfg(feature = "std")] +extern crate std; + +extern crate alloc; + mod array; mod builder; mod endian_scalar; diff --git a/rust/flatbuffers/src/primitives.rs b/rust/flatbuffers/src/primitives.rs index b7b4942d6cd..72764b21365 100644 --- a/rust/flatbuffers/src/primitives.rs +++ b/rust/flatbuffers/src/primitives.rs @@ -14,9 +14,9 @@ * limitations under the License. */ -use std::marker::PhantomData; -use std::mem::size_of; -use std::ops::Deref; +use core::marker::PhantomData; +use core::mem::size_of; +use core::ops::Deref; use crate::endian_scalar::{emplace_scalar, read_scalar, read_scalar_at}; use crate::follow::Follow; diff --git a/rust/flatbuffers/src/push.rs b/rust/flatbuffers/src/push.rs index 72ff88cd719..8bb8fe9a7df 100644 --- a/rust/flatbuffers/src/push.rs +++ b/rust/flatbuffers/src/push.rs @@ -14,8 +14,8 @@ * limitations under the License. */ -use std::cmp::max; -use std::mem::{align_of, size_of}; +use core::cmp::max; +use core::mem::{align_of, size_of}; use crate::endian_scalar::emplace_scalar; diff --git a/rust/flatbuffers/src/vector.rs b/rust/flatbuffers/src/vector.rs index fe46c503691..9237df1fa6b 100644 --- a/rust/flatbuffers/src/vector.rs +++ b/rust/flatbuffers/src/vector.rs @@ -14,12 +14,12 @@ * limitations under the License. */ -use std::fmt::{Debug, Formatter, Result}; -use std::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator}; -use std::marker::PhantomData; -use std::mem::size_of; -use std::slice::from_raw_parts; -use std::str::from_utf8_unchecked; +use core::fmt::{Debug, Formatter, Result}; +use core::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator}; +use core::marker::PhantomData; +use core::mem::size_of; +use core::slice::from_raw_parts; +use core::str::from_utf8_unchecked; use crate::endian_scalar::read_scalar_at; #[cfg(target_endian = "little")] diff --git a/rust/flatbuffers/src/verifier.rs b/rust/flatbuffers/src/verifier.rs index 12a02f96503..0e8cb27db88 100644 --- a/rust/flatbuffers/src/verifier.rs +++ b/rust/flatbuffers/src/verifier.rs @@ -1,6 +1,9 @@ use crate::follow::Follow; use crate::{ForwardsUOffset, SOffsetT, SkipSizePrefix, UOffsetT, VOffsetT, Vector, SIZE_UOFFSET}; -use std::ops::Range; +use alloc::vec::Vec; +use core::ops::Range; + +#[cfg(feature = "std")] use thiserror::Error; /// Traces the location of data errors. Not populated for Dos detecting errors. @@ -23,7 +26,7 @@ pub enum ErrorTraceDetail { } #[derive(PartialEq, Eq, Default, Debug, Clone)] pub struct ErrorTrace(Vec); -impl std::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace { +impl core::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace { #[inline] fn as_ref(&self) -> &[ErrorTraceDetail] { &self.0 @@ -32,49 +35,65 @@ impl std::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace { /// Describes how a flatuffer is invalid and, for data errors, roughly where. No extra tracing /// information is given for DoS detecting errors since it will probably be a lot. -#[derive(Clone, Error, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Error))] pub enum InvalidFlatbuffer { - #[error("Missing required field `{required}`.\n{error_trace}")] + #[cfg_attr( + feature = "std", + error("Missing required field `{required}`.\n{error_trace}") + )] MissingRequiredField { required: &'static str, error_trace: ErrorTrace, }, - #[error( - "Union exactly one of union discriminant (`{field_type}`) and value \ + #[cfg_attr( + feature = "std", + error( + "Union exactly one of union discriminant (`{field_type}`) and value \ (`{field}`) are present.\n{error_trace}" + ) )] InconsistentUnion { field: &'static str, field_type: &'static str, error_trace: ErrorTrace, }, - #[error("Utf8 error for string in {range:?}: {error}\n{error_trace}")] + #[cfg_attr( + feature = "std", + error("Utf8 error for string in {range:?}: {error}\n{error_trace}") + )] Utf8Error { - #[source] - error: std::str::Utf8Error, + #[cfg_attr(feature = "std", source)] + error: core::str::Utf8Error, range: Range, error_trace: ErrorTrace, }, - #[error("String in range [{}, {}) is missing its null terminator.\n{error_trace}", - range.start, range.end)] + #[cfg_attr(feature = "std", error("String in range [{}, {}) is missing its null terminator.\n{error_trace}", + range.start, range.end))] MissingNullTerminator { range: Range, error_trace: ErrorTrace, }, - #[error("Type `{unaligned_type}` at position {position} is unaligned.\n{error_trace}")] + #[cfg_attr( + feature = "std", + error("Type `{unaligned_type}` at position {position} is unaligned.\n{error_trace}") + )] Unaligned { position: usize, unaligned_type: &'static str, error_trace: ErrorTrace, }, - #[error("Range [{}, {}) is out of bounds.\n{error_trace}", range.start, range.end)] + #[cfg_attr(feature = "std", error("Range [{}, {}) is out of bounds.\n{error_trace}", range.start, range.end))] RangeOutOfBounds { range: Range, error_trace: ErrorTrace, }, - #[error( - "Signed offset at position {position} has value {soffset} which points out of bounds.\ + #[cfg_attr( + feature = "std", + error( + "Signed offset at position {position} has value {soffset} which points out of bounds.\ \n{error_trace}" + ) )] SignedOffsetOutOfBounds { soffset: SOffsetT, @@ -82,16 +101,16 @@ pub enum InvalidFlatbuffer { error_trace: ErrorTrace, }, // Dos detecting errors. These do not get error traces since it will probably be very large. - #[error("Too many tables.")] + #[cfg_attr(feature = "std", error("Too many tables."))] TooManyTables, - #[error("Apparent size too large.")] + #[cfg_attr(feature = "std", error("Apparent size too large."))] ApparentSizeTooLarge, - #[error("Nested table depth limit reached.")] + #[cfg_attr(feature = "std", error("Nested table depth limit reached."))] DepthLimitReached, } -impl std::fmt::Display for ErrorTrace { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Display for ErrorTrace { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { use ErrorTraceDetail::*; for e in self.0.iter() { match e { @@ -125,7 +144,7 @@ impl std::fmt::Display for ErrorTrace { } } -pub type Result = std::prelude::v1::Result; +pub type Result = core::prelude::v1::Result; impl InvalidFlatbuffer { fn new_range_oob(start: usize, end: usize) -> Result { @@ -245,11 +264,11 @@ impl<'opts, 'buf> Verifier<'opts, 'buf> { /// `buffer[0]`. TODO(caspern). #[inline] fn is_aligned(&self, pos: usize) -> Result<()> { - if pos % std::mem::align_of::() == 0 { + if pos % core::mem::align_of::() == 0 { Ok(()) } else { Err(InvalidFlatbuffer::Unaligned { - unaligned_type: std::any::type_name::(), + unaligned_type: core::any::type_name::(), position: pos, error_trace: Default::default(), }) @@ -271,7 +290,7 @@ impl<'opts, 'buf> Verifier<'opts, 'buf> { #[inline] pub fn in_buffer(&mut self, pos: usize) -> Result<()> { self.is_aligned::(pos)?; - self.range_in_buffer(pos, std::mem::size_of::()) + self.range_in_buffer(pos, core::mem::size_of::()) } #[inline] fn get_u16(&mut self, pos: usize) -> Result { @@ -416,7 +435,7 @@ impl<'ver, 'opts, 'buf> TableVerifier<'ver, 'opts, 'buf> { where Key: Follow<'buf> + Verifiable, UnionVerifier: - (std::ops::FnOnce(>::Inner, &mut Verifier, usize) -> Result<()>), + (core::ops::FnOnce(>::Inner, &mut Verifier, usize) -> Result<()>), // NOTE: >::Inner == Key { // TODO(caspern): how to trace vtable errors? @@ -468,14 +487,14 @@ impl Verifiable for ForwardsUOffset { } /// Checks and returns the range containing the flatbuffers vector. -fn verify_vector_range(v: &mut Verifier, pos: usize) -> Result> { +fn verify_vector_range(v: &mut Verifier, pos: usize) -> Result> { let len = v.get_uoffset(pos)? as usize; let start = pos.saturating_add(SIZE_UOFFSET); v.is_aligned::(start)?; - let size = len.saturating_mul(std::mem::size_of::()); + let size = len.saturating_mul(core::mem::size_of::()); let end = start.saturating_add(size); v.range_in_buffer(start, size)?; - Ok(std::ops::Range { start, end }) + Ok(core::ops::Range { start, end }) } pub trait SimpleToVerifyInSlice {} @@ -509,7 +528,7 @@ impl Verifiable for Vector<'_, ForwardsUOffset> { #[inline] fn run_verifier(v: &mut Verifier, pos: usize) -> Result<()> { let range = verify_vector_range::>(v, pos)?; - let size = std::mem::size_of::>(); + let size = core::mem::size_of::>(); for (i, element_pos) in range.step_by(size).enumerate() { trace_elem( >::run_verifier(v, element_pos), @@ -526,7 +545,7 @@ impl<'a> Verifiable for &'a str { fn run_verifier(v: &mut Verifier, pos: usize) -> Result<()> { let range = verify_vector_range::(v, pos)?; let has_null_terminator = v.buffer.get(range.end).map(|&b| b == 0).unwrap_or(false); - let s = std::str::from_utf8(&v.buffer[range.clone()]); + let s = core::str::from_utf8(&v.buffer[range.clone()]); if let Err(error) = s { return Err(InvalidFlatbuffer::Utf8Error { error, diff --git a/rust/flatbuffers/src/vtable_writer.rs b/rust/flatbuffers/src/vtable_writer.rs index 92e8522eb27..9b61dac7fcb 100644 --- a/rust/flatbuffers/src/vtable_writer.rs +++ b/rust/flatbuffers/src/vtable_writer.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::ptr::write_bytes; +use core::ptr::write_bytes; use crate::endian_scalar::emplace_scalar; use crate::primitives::*; diff --git a/samples/csharp_sample.sh b/samples/csharp_sample.sh index ea472ed9c05..465da209794 100755 --- a/samples/csharp_sample.sh +++ b/samples/csharp_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/dart_sample.sh b/samples/dart_sample.sh index 40326790dfc..6192e738a33 100755 --- a/samples/dart_sample.sh +++ b/samples/dart_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo # # Copyright 2018 Dan Field. All rights reserved. diff --git a/samples/go_sample.sh b/samples/go_sample.sh index 13a96c12932..5131ed3c3b4 100755 --- a/samples/go_sample.sh +++ b/samples/go_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/java_sample.sh b/samples/java_sample.sh index bd1315f4ce4..53064906557 100755 --- a/samples/java_sample.sh +++ b/samples/java_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/javascript_sample.sh b/samples/javascript_sample.sh index 4bbc478d7f5..805719d9e4e 100755 --- a/samples/javascript_sample.sh +++ b/samples/javascript_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/kotlin_sample.sh b/samples/kotlin_sample.sh index ca4ea86dca8..bd9e0d6fb88 100755 --- a/samples/kotlin_sample.sh +++ b/samples/kotlin_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/php_sample.sh b/samples/php_sample.sh index c23edc380f9..0d7d61b4fdb 100755 --- a/samples/php_sample.sh +++ b/samples/php_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/python_sample.sh b/samples/python_sample.sh index ca5de2b03fd..a59565f5fe4 100755 --- a/samples/python_sample.sh +++ b/samples/python_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/rust_generated/my_game/sample/color_generated.rs b/samples/rust_generated/my_game/sample/color_generated.rs index 1ef1d31b5c7..18a050834d2 100644 --- a/samples/rust_generated/my_game/sample/color_generated.rs +++ b/samples/rust_generated/my_game/sample/color_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_COLOR: i8 = 0; @@ -42,8 +45,8 @@ impl Color { } } } -impl std::fmt::Debug for Color { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Color { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -89,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for Color { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/samples/rust_generated/my_game/sample/equipment_generated.rs b/samples/rust_generated/my_game/sample/equipment_generated.rs index 919958a355a..3d1176e469a 100644 --- a/samples/rust_generated/my_game/sample/equipment_generated.rs +++ b/samples/rust_generated/my_game/sample/equipment_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_EQUIPMENT: u8 = 0; @@ -38,8 +41,8 @@ impl Equipment { } } } -impl std::fmt::Debug for Equipment { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Equipment { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -85,7 +88,6 @@ impl<'a> flatbuffers::Verifiable for Equipment { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -121,7 +123,7 @@ impl EquipmentT { /// If the union variant matches, return the owned WeaponT, setting the union to NONE. pub fn take_weapon(&mut self) -> Option> { if let Self::Weapon(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Weapon(w) = v { Some(w) } else { diff --git a/samples/rust_generated/my_game/sample/monster_generated.rs b/samples/rust_generated/my_game/sample/monster_generated.rs index d8988321247..2cbc1678bcf 100644 --- a/samples/rust_generated/my_game/sample/monster_generated.rs +++ b/samples/rust_generated/my_game/sample/monster_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -156,7 +159,6 @@ impl flatbuffers::Verifiable for Monster<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("pos", Self::VT_POS, false)? .visit_field::("mana", Self::VT_MANA, false)? @@ -265,8 +267,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl std::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Monster"); ds.field("pos", &self.pos()); ds.field("mana", &self.mana()); diff --git a/samples/rust_generated/my_game/sample/vec_3_generated.rs b/samples/rust_generated/my_game/sample/vec_3_generated.rs index 33805b3f90a..22e40cbae88 100644 --- a/samples/rust_generated/my_game/sample/vec_3_generated.rs +++ b/samples/rust_generated/my_game/sample/vec_3_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Vec3, aligned to 4 #[repr(transparent)] @@ -13,8 +16,8 @@ impl Default for Vec3 { Self([0; 12]) } } -impl std::fmt::Debug for Vec3 { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Vec3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Vec3") .field("x", &self.x()) .field("y", &self.y()) @@ -44,7 +47,7 @@ impl<'b> flatbuffers::Push for Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -55,7 +58,7 @@ impl<'b> flatbuffers::Push for &'b Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -66,7 +69,6 @@ impl<'a> flatbuffers::Verifiable for Vec3 { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -89,70 +91,70 @@ impl<'a> Vec3 { } pub fn x(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_x(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn y(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_y(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn z(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[8..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_z(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/samples/rust_generated/my_game/sample/weapon_generated.rs b/samples/rust_generated/my_game/sample/weapon_generated.rs index e2cede9d666..7fb946cf328 100644 --- a/samples/rust_generated/my_game/sample/weapon_generated.rs +++ b/samples/rust_generated/my_game/sample/weapon_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum WeaponOffset {} #[derive(Copy, Clone, PartialEq)] @@ -68,7 +71,6 @@ impl flatbuffers::Verifiable for Weapon<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("name", Self::VT_NAME, false)? .visit_field::("damage", Self::VT_DAMAGE, false)? @@ -117,8 +119,8 @@ impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> { } } -impl std::fmt::Debug for Weapon<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for Weapon<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Weapon"); ds.field("name", &self.name()); ds.field("damage", &self.damage()); diff --git a/scripts/check-generate-code.sh b/scripts/check-generate-code.sh index 1f2d84d4d56..019999ea3e3 100755 --- a/scripts/check-generate-code.sh +++ b/scripts/check-generate-code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2018 Google Inc. All rights reserved. # diff --git a/scripts/check-grpc-generated-code.sh b/scripts/check-grpc-generated-code.sh index 4541be16eff..95d400bf58e 100755 --- a/scripts/check-grpc-generated-code.sh +++ b/scripts/check-grpc-generated-code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index 813a4c199bf..2e5d6f722c7 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -322,6 +322,7 @@ class RustGenerator : public BaseGenerator { "yield", // other rust terms we should not use + "core" "std", "usize", "isize", @@ -381,10 +382,13 @@ class RustGenerator : public BaseGenerator { if (symbol.generated) continue; code_.Clear(); code_ += "// " + std::string(FlatBuffersGeneratedWarning()); + code_ += "extern crate alloc;"; + code_ += "extern crate core;"; code_ += "extern crate flatbuffers;"; - code_ += "use std::mem;"; - code_ += "use std::cmp::Ordering;"; - code_ += "use self::flatbuffers::{EndianScalar, Follow};"; + code_ += "use self::alloc::{boxed::Box, vec::Vec};"; + code_ += "use self::alloc::string::{String, ToString as _};"; + code_ += "use self::core::{cmp::Ordering, fmt, mem, ptr, slice};"; + code_ += "use self::flatbuffers::{EndianScalar, Follow, Verifiable};"; code_ += "use super::*;"; cur_name_space_ = symbol.defined_namespace; gen_symbol(symbol); @@ -826,10 +830,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; // Generate Debug. Unknown variants are printed like "". - code_ += "impl std::fmt::Debug for {{ENUM_NAME}} {"; + code_ += "impl fmt::Debug for {{ENUM_NAME}} {"; code_ += - " fn fmt(&self, f: &mut std::fmt::Formatter) ->" - " std::fmt::Result {"; + " fn fmt(&self, f: &mut fmt::Formatter) ->" + " fmt::Result {"; code_ += " if let Some(name) = self.variant_name() {"; code_ += " f.write_str(name)"; code_ += " } else {"; @@ -885,7 +889,6 @@ class RustGenerator : public BaseGenerator { code_ += " fn run_verifier("; code_ += " v: &mut flatbuffers::Verifier, pos: usize"; code_ += " ) -> Result<(), flatbuffers::InvalidFlatbuffer> {"; - code_ += " use self::flatbuffers::Verifiable;"; code_ += " {{BASE_TYPE}}::run_verifier(v, pos)"; code_ += " }"; code_ += "}"; @@ -981,7 +984,7 @@ class RustGenerator : public BaseGenerator { "pub fn take_{{U_ELEMENT_NAME}}(&mut self) -> " "Option> {"; code_ += " if let Self::{{NATIVE_VARIANT}}(_) = self {"; - code_ += " let v = std::mem::replace(self, Self::NONE);"; + code_ += " let v = mem::replace(self, Self::NONE);"; code_ += " if let Self::{{NATIVE_VARIANT}}(w) = v {"; code_ += " Some(w)"; code_ += " } else {"; @@ -1869,14 +1872,12 @@ class RustGenerator : public BaseGenerator { if (field.IsRequired()) { code_ += "{{NESTED}}<'a> {"; code_ += " let data = self.{{FIELD_NAME}}();"; - code_ += " use flatbuffers::Follow;"; code_ += " >>" "::follow(data, 0)"; } else { code_ += "Option<{{NESTED}}<'a>> {"; code_ += " self.{{FIELD_NAME}}().map(|data| {"; - code_ += " use flatbuffers::Follow;"; code_ += " >>" "::follow(data, 0)"; @@ -1937,7 +1938,6 @@ class RustGenerator : public BaseGenerator { code_ += " fn run_verifier("; code_ += " v: &mut flatbuffers::Verifier, pos: usize"; code_ += " ) -> Result<(), flatbuffers::InvalidFlatbuffer> {"; - code_ += " use self::flatbuffers::Verifiable;"; code_ += " v.visit_table(pos)?\\"; // Escape newline and insert it onthe next line so we can end the builder // with a nice semicolon. @@ -2078,10 +2078,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; code_ += ""; - code_ += "impl std::fmt::Debug for {{STRUCT_NAME}}<'_> {"; + code_ += "impl fmt::Debug for {{STRUCT_NAME}}<'_> {"; code_ += - " fn fmt(&self, f: &mut std::fmt::Formatter<'_>" - ") -> std::fmt::Result {"; + " fn fmt(&self, f: &mut fmt::Formatter<'_>" + ") -> fmt::Result {"; code_ += " let mut ds = f.debug_struct(\"{{STRUCT_NAME}}\");"; ForAllTableFields(struct_def, [&](const FieldDef &field) { if (GetFullType(field.value.type) == ftUnionValue) { @@ -2302,7 +2302,7 @@ class RustGenerator : public BaseGenerator { code_ += "#[inline]"; code_ += "pub fn key_compare_with_value(&self, val: {{KEY_TYPE}}) -> " - "::std::cmp::Ordering {"; + " Ordering {"; code_ += " let key = self.{{FIELD_NAME}}();"; code_ += " key.cmp({{REF}}val)"; code_ += "}"; @@ -2565,10 +2565,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; // Debug for structs. - code_ += "impl std::fmt::Debug for {{STRUCT_NAME}} {"; + code_ += "impl fmt::Debug for {{STRUCT_NAME}} {"; code_ += - " fn fmt(&self, f: &mut std::fmt::Formatter" - ") -> std::fmt::Result {"; + " fn fmt(&self, f: &mut fmt::Formatter" + ") -> fmt::Result {"; code_ += " f.debug_struct(\"{{STRUCT_NAME}}\")"; ForAllStructFields(struct_def, [&](const FieldDef &unused) { (void)unused; @@ -2604,7 +2604,7 @@ class RustGenerator : public BaseGenerator { code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {"; code_ += " let src = unsafe {"; code_ += - " ::std::slice::from_raw_parts(" + " slice::from_raw_parts(" "self as *const {{STRUCT_NAME}} as *const u8, Self::size())"; code_ += " };"; code_ += " dst.copy_from_slice(src);"; @@ -2617,7 +2617,7 @@ class RustGenerator : public BaseGenerator { code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {"; code_ += " let src = unsafe {"; code_ += - " ::std::slice::from_raw_parts(" + " slice::from_raw_parts(" "*self as *const {{STRUCT_NAME}} as *const u8, Self::size())"; code_ += " };"; code_ += " dst.copy_from_slice(src);"; @@ -2632,7 +2632,6 @@ class RustGenerator : public BaseGenerator { code_ += " fn run_verifier("; code_ += " v: &mut flatbuffers::Verifier, pos: usize"; code_ += " ) -> Result<(), flatbuffers::InvalidFlatbuffer> {"; - code_ += " use self::flatbuffers::Verifiable;"; code_ += " v.in_buffer::(pos)"; code_ += " }"; code_ += "}"; @@ -2680,15 +2679,15 @@ class RustGenerator : public BaseGenerator { } else { code_ += "pub fn {{FIELD_NAME}}(&self) -> {{FIELD_TYPE}} {"; code_ += - " let mut mem = core::mem::MaybeUninit::" + " let mut uninit = mem::MaybeUninit::" "<{{FIELD_TYPE}}>::uninit();"; code_ += " unsafe {"; - code_ += " core::ptr::copy_nonoverlapping("; + code_ += " ptr::copy_nonoverlapping("; code_ += " self.0[{{FIELD_OFFSET}}..].as_ptr(),"; - code_ += " mem.as_mut_ptr() as *mut u8,"; - code_ += " core::mem::size_of::<{{FIELD_TYPE}}>(),"; + code_ += " uninit.as_mut_ptr() as *mut u8,"; + code_ += " mem::size_of::<{{FIELD_TYPE}}>(),"; code_ += " );"; - code_ += " mem.assume_init()"; + code_ += " uninit.assume_init()"; code_ += " }.from_little_endian()"; } code_ += "}\n"; @@ -2718,7 +2717,7 @@ class RustGenerator : public BaseGenerator { NumToString(InlineSize(field.value.type))); code_ += "pub fn set_{{FIELD_NAME}}(&mut self, x: &{{FIELD_TYPE}}) {"; code_ += " unsafe {"; - code_ += " std::ptr::copy("; + code_ += " ptr::copy("; code_ += " x.as_ptr() as *const u8,"; code_ += " self.0.as_mut_ptr().add({{FIELD_OFFSET}}),"; code_ += " {{FIELD_SIZE}},"; @@ -2729,10 +2728,10 @@ class RustGenerator : public BaseGenerator { code_ += "pub fn set_{{FIELD_NAME}}(&mut self, x: {{FIELD_TYPE}}) {"; code_ += " let x_le = x.to_little_endian();"; code_ += " unsafe {"; - code_ += " core::ptr::copy_nonoverlapping("; + code_ += " ptr::copy_nonoverlapping("; code_ += " &x_le as *const {{FIELD_TYPE}} as *const u8,"; code_ += " self.0[{{FIELD_OFFSET}}..].as_mut_ptr(),"; - code_ += " core::mem::size_of::<{{FIELD_TYPE}}>(),"; + code_ += " mem::size_of::<{{FIELD_TYPE}}>(),"; code_ += " );"; code_ += " }"; } @@ -2831,11 +2830,8 @@ class RustGenerator : public BaseGenerator { } } } - code_ += indent + "use std::mem;"; - code_ += indent + "use std::cmp::Ordering;"; - code_ += ""; - code_ += indent + "extern crate flatbuffers;"; - code_ += indent + "use self::flatbuffers::{EndianScalar, Follow};"; + code_ += indent + "use core::{cmp::Ordering, mem};"; + code_ += indent + "use flatbuffers::{EndianScalar, Follow};"; } // Set up the correct namespace. This opens a namespace if the current diff --git a/tests/GoTest.sh b/tests/GoTest.sh index 8cbadcb56f6..605e88689a3 100755 --- a/tests/GoTest.sh +++ b/tests/GoTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/usr/bin/env bash -eu # # Copyright 2014 Google Inc. All rights reserved. # diff --git a/tests/JavaTest.sh b/tests/JavaTest.sh index 099447e8bb6..8fe2a41859e 100755 --- a/tests/JavaTest.sh +++ b/tests/JavaTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2014 Google Inc. All rights reserved. # diff --git a/tests/LuaTest.sh b/tests/LuaTest.sh index d736a6b1ea2..a68dcecfed2 100755 --- a/tests/LuaTest.sh +++ b/tests/LuaTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/usr/bin/env bash -eu # # Copyright 2019 Google Inc. All rights reserved. # diff --git a/tests/PythonTest.sh b/tests/PythonTest.sh index b387ec1b2e0..4a6c48c042e 100755 --- a/tests/PythonTest.sh +++ b/tests/PythonTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/usr/bin/env bash -eu # # Copyright 2014 Google Inc. All rights reserved. # diff --git a/tests/RustTest.bat b/tests/RustTest.bat index 1473ffbed25..d2bcca7a64e 100644 --- a/tests/RustTest.bat +++ b/tests/RustTest.bat @@ -18,6 +18,7 @@ rem Compile then run the Rust test. rem TODO(rw): how do we make this script abort the calling script in appveyor? cd rust_usage_test +cargo test --no-default-features -- --quiet || exit /b 1 cargo test -- --quiet || exit /b 1 cargo run --bin=flatbuffers_alloc_check || exit /b 1 cargo run --bin=flexbuffers_alloc_check || exit /b 1 diff --git a/tests/RustTest.sh b/tests/RustTest.sh index 7a7894ad64d..ec4c196fdf6 100755 --- a/tests/RustTest.sh +++ b/tests/RustTest.sh @@ -32,10 +32,13 @@ function check_test_result() { } cd ./rust_usage_test + +cargo test $TARGET_FLAG --no-default-features -- --quiet +check_test_result "Rust tests without default features" + cargo test $TARGET_FLAG -- --quiet check_test_result "Rust tests" - cargo run $TARGET_FLAG --bin=flatbuffers_alloc_check check_test_result "Rust flatbuffers heap alloc test" diff --git a/tests/arrays_test/my_game/example/array_struct_generated.rs b/tests/arrays_test/my_game/example/array_struct_generated.rs index ded58e6e3f7..868a4913b91 100644 --- a/tests/arrays_test/my_game/example/array_struct_generated.rs +++ b/tests/arrays_test/my_game/example/array_struct_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct ArrayStruct, aligned to 8 #[repr(transparent)] @@ -13,8 +16,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 fmt::Debug for ArrayStruct { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("ArrayStruct") .field("a", &self.a()) .field("b", &self.b()) @@ -47,7 +50,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()) + slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -58,7 +61,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()) + slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -69,7 +72,6 @@ impl<'a> flatbuffers::Verifiable for ArrayStruct { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -98,24 +100,24 @@ impl<'a> ArrayStruct { } pub fn a(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -129,24 +131,24 @@ impl<'a> ArrayStruct { } pub fn c(&self) -> i8 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[64..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_c(&mut self, x: i8) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i8 as *const u8, self.0[64..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -157,7 +159,7 @@ impl<'a> ArrayStruct { pub fn set_d(&mut self, x: &[NestedStruct; 2]) { unsafe { - std::ptr::copy( + ptr::copy( x.as_ptr() as *const u8, self.0.as_mut_ptr().add(72), 64, @@ -166,24 +168,24 @@ impl<'a> ArrayStruct { } pub fn e(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[136..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_e(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[136..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/arrays_test/my_game/example/array_table_generated.rs b/tests/arrays_test/my_game/example/array_table_generated.rs index 9a2fe7d03f0..79e3d89b32f 100644 --- a/tests/arrays_test/my_game/example/array_table_generated.rs +++ b/tests/arrays_test/my_game/example/array_table_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum ArrayTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for ArrayTable<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("a", Self::VT_A, false)? .finish(); @@ -102,8 +104,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 fmt::Debug for ArrayTable<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("ArrayTable"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/arrays_test/my_game/example/nested_struct_generated.rs b/tests/arrays_test/my_game/example/nested_struct_generated.rs index 511c64aaf4c..507abb4d814 100644 --- a/tests/arrays_test/my_game/example/nested_struct_generated.rs +++ b/tests/arrays_test/my_game/example/nested_struct_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct NestedStruct, aligned to 8 #[repr(transparent)] @@ -13,8 +16,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 fmt::Debug for NestedStruct { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("NestedStruct") .field("a", &self.a()) .field("b", &self.b()) @@ -45,7 +48,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()) + slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -56,7 +59,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()) + slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -67,7 +70,6 @@ impl<'a> flatbuffers::Verifiable for NestedStruct { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -100,24 +102,24 @@ impl<'a> NestedStruct { } pub fn b(&self) -> TestEnum { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[8..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_b(&mut self, x: TestEnum) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const TestEnum as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -128,7 +130,7 @@ impl<'a> NestedStruct { pub fn set_c(&mut self, x: &[TestEnum; 2]) { unsafe { - std::ptr::copy( + ptr::copy( x.as_ptr() as *const u8, self.0.as_mut_ptr().add(9), 2, diff --git a/tests/arrays_test/my_game/example/test_enum_generated.rs b/tests/arrays_test/my_game/example/test_enum_generated.rs index 6dcc1cb970b..1b7cc66e87c 100644 --- a/tests/arrays_test/my_game/example/test_enum_generated.rs +++ b/tests/arrays_test/my_game/example/test_enum_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_TEST_ENUM: i8 = 0; @@ -42,8 +45,8 @@ impl TestEnum { } } } -impl std::fmt::Debug for TestEnum { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for TestEnum { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -89,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for TestEnum { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/docker/languages/Dockerfile.testing.rust.no_std b/tests/docker/languages/Dockerfile.testing.rust.no_std new file mode 100644 index 00000000000..05ce7513605 --- /dev/null +++ b/tests/docker/languages/Dockerfile.testing.rust.no_std @@ -0,0 +1,7 @@ +FROM rust +WORKDIR /code +ADD . . +WORKDIR /code/rust/flatbuffers +RUN rustup default nightly +RUN rustc --version +RUN cargo test --no-default-features diff --git a/tests/generate_code.sh b/tests/generate_code.sh index ccb262bb47f..b4ad29bb4bc 100755 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/tests/include_test1/my_game/other_name_space/from_include_generated.rs b/tests/include_test1/my_game/other_name_space/from_include_generated.rs index 048bafdb8d0..9112c751e13 100644 --- a/tests/include_test1/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test1/my_game/other_name_space/from_include_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; @@ -34,8 +37,8 @@ impl FromInclude { } } } -impl std::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for FromInclude { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -81,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for FromInclude { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i64::run_verifier(v, pos) } } diff --git a/tests/include_test1/my_game/other_name_space/table_b_generated.rs b/tests/include_test1/my_game/other_name_space/table_b_generated.rs index d7aee6407b1..7c9a8fdbdee 100644 --- a/tests/include_test1/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test1/my_game/other_name_space/table_b_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for TableB<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("a", Self::VT_A, false)? .finish(); @@ -102,8 +104,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 fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/include_test1/my_game/other_name_space/unused_generated.rs b/tests/include_test1/my_game/other_name_space/unused_generated.rs index f3fb099ff61..cd9a96d4c97 100644 --- a/tests/include_test1/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test1/my_game/other_name_space/unused_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -13,8 +16,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 fmt::Debug for Unused { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -42,7 +45,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()) + slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -53,7 +56,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()) + slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -64,7 +67,6 @@ impl<'a> flatbuffers::Verifiable for Unused { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -83,24 +85,24 @@ impl<'a> Unused { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/include_test1/table_a_generated.rs b/tests/include_test1/table_a_generated.rs index 89c6a5fc80c..91274b1efdf 100644 --- a/tests/include_test1/table_a_generated.rs +++ b/tests/include_test1/table_a_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for TableA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("b", Self::VT_B, false)? .finish(); @@ -102,8 +104,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 fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/include_test2/my_game/other_name_space/from_include_generated.rs b/tests/include_test2/my_game/other_name_space/from_include_generated.rs index 048bafdb8d0..9112c751e13 100644 --- a/tests/include_test2/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test2/my_game/other_name_space/from_include_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; @@ -34,8 +37,8 @@ impl FromInclude { } } } -impl std::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for FromInclude { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -81,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for FromInclude { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i64::run_verifier(v, pos) } } diff --git a/tests/include_test2/my_game/other_name_space/table_b_generated.rs b/tests/include_test2/my_game/other_name_space/table_b_generated.rs index d7aee6407b1..7c9a8fdbdee 100644 --- a/tests/include_test2/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test2/my_game/other_name_space/table_b_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for TableB<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("a", Self::VT_A, false)? .finish(); @@ -102,8 +104,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 fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/include_test2/my_game/other_name_space/unused_generated.rs b/tests/include_test2/my_game/other_name_space/unused_generated.rs index f3fb099ff61..cd9a96d4c97 100644 --- a/tests/include_test2/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test2/my_game/other_name_space/unused_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -13,8 +16,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 fmt::Debug for Unused { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -42,7 +45,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()) + slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -53,7 +56,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()) + slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -64,7 +67,6 @@ impl<'a> flatbuffers::Verifiable for Unused { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -83,24 +85,24 @@ impl<'a> Unused { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/include_test2/table_a_generated.rs b/tests/include_test2/table_a_generated.rs index 89c6a5fc80c..91274b1efdf 100644 --- a/tests/include_test2/table_a_generated.rs +++ b/tests/include_test2/table_a_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for TableA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("b", Self::VT_B, false)? .finish(); @@ -102,8 +104,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 fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/keyword_test/keyword_test/abc_generated.rs b/tests/keyword_test/keyword_test/abc_generated.rs index 99b43e46659..9a8ece71681 100644 --- a/tests/keyword_test/keyword_test/abc_generated.rs +++ b/tests/keyword_test/keyword_test/abc_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ABC: i32 = 0; @@ -42,8 +45,8 @@ impl ABC { } } } -impl std::fmt::Debug for ABC { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for ABC { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -89,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for ABC { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i32::run_verifier(v, pos) } } diff --git a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs index 17bcd0c097a..0e976ea5172 100644 --- a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum KeywordsInTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -74,7 +77,6 @@ impl flatbuffers::Verifiable for KeywordsInTable<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("is", Self::VT_IS, false)? .visit_field::("private", Self::VT_PRIVATE, false)? @@ -130,8 +132,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 fmt::Debug for KeywordsInTable<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("KeywordsInTable"); ds.field("is", &self.is()); ds.field("private", &self.private()); diff --git a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs index cf03797f9d4..35f7533c884 100644 --- a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_KEYWORDS_IN_UNION: u8 = 0; @@ -42,8 +45,8 @@ impl KeywordsInUnion { } } } -impl std::fmt::Debug for KeywordsInUnion { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for KeywordsInUnion { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -89,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for KeywordsInUnion { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -128,7 +130,7 @@ impl KeywordsInUnionT { /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. pub fn take_static_(&mut self) -> Option> { if let Self::Static_(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Static_(w) = v { Some(w) } else { @@ -149,7 +151,7 @@ impl KeywordsInUnionT { /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. pub fn take_internal(&mut self) -> Option> { if let Self::Internal(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Internal(w) = v { Some(w) } else { diff --git a/tests/keyword_test/keyword_test/public_generated.rs b/tests/keyword_test/keyword_test/public_generated.rs index 2de4c0b24e7..62dbe4f20c6 100644 --- a/tests/keyword_test/keyword_test/public_generated.rs +++ b/tests/keyword_test/keyword_test/public_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_PUBLIC: i32 = 0; @@ -34,8 +37,8 @@ impl public { } } } -impl std::fmt::Debug for public { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for public { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -81,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for public { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i32::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/example/ability_generated.rs b/tests/monster_test/my_game/example/ability_generated.rs index 444e41b8f70..63e097bb770 100644 --- a/tests/monster_test/my_game/example/ability_generated.rs +++ b/tests/monster_test/my_game/example/ability_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Ability, aligned to 4 #[repr(transparent)] @@ -13,8 +16,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 fmt::Debug for Ability { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Ability") .field("id", &self.id()) .field("distance", &self.distance()) @@ -43,7 +46,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()) + slice::from_raw_parts(self as *const Ability as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -54,7 +57,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()) + slice::from_raw_parts(*self as *const Ability as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -65,7 +68,6 @@ impl<'a> flatbuffers::Verifiable for Ability { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -86,24 +88,24 @@ impl<'a> Ability { } pub fn id(&self) -> u32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_id(&mut self, x: u32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const u32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -114,29 +116,29 @@ 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) -> Ordering { let key = self.id(); key.cmp(&val) } pub fn distance(&self) -> u32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_distance(&mut self, x: u32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const u32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs index 321007abe08..42723b4a523 100644 --- a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY_AMBIGUOUS_ALIASES: u8 = 0; @@ -46,8 +49,8 @@ impl AnyAmbiguousAliases { } } } -impl std::fmt::Debug for AnyAmbiguousAliases { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for AnyAmbiguousAliases { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -93,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for AnyAmbiguousAliases { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -135,7 +137,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m1(&mut self) -> Option> { if let Self::M1(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M1(w) = v { Some(w) } else { @@ -156,7 +158,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M2(w) = v { Some(w) } else { @@ -177,7 +179,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m3(&mut self) -> Option> { if let Self::M3(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M3(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/any_generated.rs b/tests/monster_test/my_game/example/any_generated.rs index 6f7f6fdac49..cfaa517a19e 100644 --- a/tests/monster_test/my_game/example/any_generated.rs +++ b/tests/monster_test/my_game/example/any_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY: u8 = 0; @@ -46,8 +49,8 @@ impl Any { } } } -impl std::fmt::Debug for Any { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Any { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -93,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for Any { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -135,7 +137,7 @@ impl AnyT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_monster(&mut self) -> Option> { if let Self::Monster(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Monster(w) = v { Some(w) } else { @@ -156,7 +158,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> { if let Self::TestSimpleTableWithEnum(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::TestSimpleTableWithEnum(w) = v { Some(w) } else { @@ -177,7 +179,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> { if let Self::MyGameExample2Monster(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::MyGameExample2Monster(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs index 1749d5d7a24..3158c0bd9e9 100644 --- a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY_UNIQUE_ALIASES: u8 = 0; @@ -46,8 +49,8 @@ impl AnyUniqueAliases { } } } -impl std::fmt::Debug for AnyUniqueAliases { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for AnyUniqueAliases { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -93,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for AnyUniqueAliases { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -135,7 +137,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m(&mut self) -> Option> { if let Self::M(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M(w) = v { Some(w) } else { @@ -156,7 +158,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. pub fn take_ts(&mut self) -> Option> { if let Self::TS(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::TS(w) = v { Some(w) } else { @@ -177,7 +179,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M2(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/color_generated.rs b/tests/monster_test/my_game/example/color_generated.rs index 4a3282b4687..dc39ab70a3c 100644 --- a/tests/monster_test/my_game/example/color_generated.rs +++ b/tests/monster_test/my_game/example/color_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[allow(non_upper_case_globals)] mod bitflags_color { @@ -59,7 +62,6 @@ impl<'a> flatbuffers::Verifiable for Color { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/example/monster_generated.rs b/tests/monster_test/my_game/example/monster_generated.rs index d30525fde94..6e133adfad2 100644 --- a/tests/monster_test/my_game/example/monster_generated.rs +++ b/tests/monster_test/my_game/example/monster_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -365,7 +368,7 @@ impl<'a> Monster<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: & str) -> ::std::cmp::Ordering { + pub fn key_compare_with_value(&self, val: & str) -> Ordering { let key = self.name(); key.cmp(val) } @@ -409,7 +412,6 @@ impl<'a> Monster<'a> { } pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testnestedflatbuffer().map(|data| { - use flatbuffers::Follow; >>::follow(data, 0) }) } @@ -559,7 +561,6 @@ impl<'a> Monster<'a> { } pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testrequirednestedflatbuffer().map(|data| { - use flatbuffers::Follow; >>::follow(data, 0) }) } @@ -664,7 +665,6 @@ impl flatbuffers::Verifiable for Monster<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("pos", Self::VT_POS, false)? .visit_field::("mana", Self::VT_MANA, false)? @@ -1068,8 +1068,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl std::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Monster"); ds.field("pos", &self.pos()); ds.field("mana", &self.mana()); diff --git a/tests/monster_test/my_game/example/race_generated.rs b/tests/monster_test/my_game/example/race_generated.rs index ab012f9bfaa..25c3cff86f9 100644 --- a/tests/monster_test/my_game/example/race_generated.rs +++ b/tests/monster_test/my_game/example/race_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_RACE: i8 = -1; @@ -46,8 +49,8 @@ impl Race { } } } -impl std::fmt::Debug for Race { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Race { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -93,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for Race { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/example/referrable_generated.rs b/tests/monster_test/my_game/example/referrable_generated.rs index b706f1d8c52..237ac5c493d 100644 --- a/tests/monster_test/my_game/example/referrable_generated.rs +++ b/tests/monster_test/my_game/example/referrable_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum ReferrableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -57,7 +60,7 @@ impl<'a> Referrable<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: u64) -> ::std::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u64) -> Ordering { let key = self.id(); key.cmp(&val) } @@ -68,7 +71,6 @@ impl flatbuffers::Verifiable for Referrable<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("id", Self::VT_ID, false)? .finish(); @@ -110,8 +112,8 @@ impl<'a: 'b, 'b> ReferrableBuilder<'a, 'b> { } } -impl std::fmt::Debug for Referrable<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for Referrable<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Referrable"); ds.field("id", &self.id()); ds.finish() diff --git a/tests/monster_test/my_game/example/stat_generated.rs b/tests/monster_test/my_game/example/stat_generated.rs index 338c44396c0..6403494b8fb 100644 --- a/tests/monster_test/my_game/example/stat_generated.rs +++ b/tests/monster_test/my_game/example/stat_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum StatOffset {} #[derive(Copy, Clone, PartialEq)] @@ -75,7 +78,7 @@ impl<'a> Stat<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: u16) -> ::std::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u16) -> Ordering { let key = self.count(); key.cmp(&val) } @@ -86,7 +89,6 @@ impl flatbuffers::Verifiable for Stat<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("id", Self::VT_ID, false)? .visit_field::("val", Self::VT_VAL, false)? @@ -142,8 +144,8 @@ impl<'a: 'b, 'b> StatBuilder<'a, 'b> { } } -impl std::fmt::Debug for Stat<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for Stat<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Stat"); ds.field("id", &self.id()); ds.field("val", &self.val()); diff --git a/tests/monster_test/my_game/example/struct_of_structs_generated.rs b/tests/monster_test/my_game/example/struct_of_structs_generated.rs index 47a1250581e..a5ae899247c 100644 --- a/tests/monster_test/my_game/example/struct_of_structs_generated.rs +++ b/tests/monster_test/my_game/example/struct_of_structs_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct StructOfStructs, aligned to 4 #[repr(transparent)] @@ -13,8 +16,8 @@ impl Default for StructOfStructs { Self([0; 20]) } } -impl std::fmt::Debug for StructOfStructs { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for StructOfStructs { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("StructOfStructs") .field("a", &self.a()) .field("b", &self.b()) @@ -44,7 +47,7 @@ impl<'b> flatbuffers::Push for StructOfStructs { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size()) + slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -55,7 +58,7 @@ impl<'b> flatbuffers::Push for &'b StructOfStructs { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size()) + slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -66,7 +69,6 @@ impl<'a> flatbuffers::Verifiable for StructOfStructs { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } diff --git a/tests/monster_test/my_game/example/test_generated.rs b/tests/monster_test/my_game/example/test_generated.rs index 5308a520bf9..b7ee0967aae 100644 --- a/tests/monster_test/my_game/example/test_generated.rs +++ b/tests/monster_test/my_game/example/test_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Test, aligned to 2 #[repr(transparent)] @@ -13,8 +16,8 @@ impl Default for Test { Self([0; 4]) } } -impl std::fmt::Debug for Test { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Test { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Test") .field("a", &self.a()) .field("b", &self.b()) @@ -43,7 +46,7 @@ impl<'b> flatbuffers::Push for Test { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Test as *const u8, Self::size()) + slice::from_raw_parts(self as *const Test as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -54,7 +57,7 @@ impl<'b> flatbuffers::Push for &'b Test { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Test as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Test as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -65,7 +68,6 @@ impl<'a> flatbuffers::Verifiable for Test { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -86,47 +88,47 @@ impl<'a> Test { } pub fn a(&self) -> i16 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i16) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i16 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn b(&self) -> i8 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[2..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_b(&mut self, x: i8) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i8 as *const u8, self.0[2..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs index 74014e74ac5..0f83417967c 100644 --- a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs +++ b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TestSimpleTableWithEnumOffset {} #[derive(Copy, Clone, PartialEq)] @@ -58,7 +61,6 @@ impl flatbuffers::Verifiable for TestSimpleTableWithEnum<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("color", Self::VT_COLOR, false)? .finish(); @@ -100,8 +102,8 @@ impl<'a: 'b, 'b> TestSimpleTableWithEnumBuilder<'a, 'b> { } } -impl std::fmt::Debug for TestSimpleTableWithEnum<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for TestSimpleTableWithEnum<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TestSimpleTableWithEnum"); ds.field("color", &self.color()); ds.finish() diff --git a/tests/monster_test/my_game/example/type_aliases_generated.rs b/tests/monster_test/my_game/example/type_aliases_generated.rs index aee59bdd1d2..da4fdb1fdc5 100644 --- a/tests/monster_test/my_game/example/type_aliases_generated.rs +++ b/tests/monster_test/my_game/example/type_aliases_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TypeAliasesOffset {} #[derive(Copy, Clone, PartialEq)] @@ -150,7 +153,6 @@ impl flatbuffers::Verifiable for TypeAliases<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("i8_", Self::VT_I8_, false)? .visit_field::("u8_", Self::VT_U8_, false)? @@ -269,8 +271,8 @@ impl<'a: 'b, 'b> TypeAliasesBuilder<'a, 'b> { } } -impl std::fmt::Debug for TypeAliases<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for TypeAliases<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TypeAliases"); ds.field("i8_", &self.i8_()); ds.field("u8_", &self.u8_()); diff --git a/tests/monster_test/my_game/example/vec_3_generated.rs b/tests/monster_test/my_game/example/vec_3_generated.rs index d4efb24eb48..8d27660592a 100644 --- a/tests/monster_test/my_game/example/vec_3_generated.rs +++ b/tests/monster_test/my_game/example/vec_3_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Vec3, aligned to 8 #[repr(transparent)] @@ -13,8 +16,8 @@ impl Default for Vec3 { Self([0; 32]) } } -impl std::fmt::Debug for Vec3 { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Vec3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Vec3") .field("x", &self.x()) .field("y", &self.y()) @@ -47,7 +50,7 @@ impl<'b> flatbuffers::Push for Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -58,7 +61,7 @@ impl<'b> flatbuffers::Push for &'b Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -69,7 +72,6 @@ impl<'a> flatbuffers::Verifiable for Vec3 { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -98,116 +100,116 @@ impl<'a> Vec3 { } pub fn x(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_x(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn y(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_y(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn z(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[8..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_z(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn test1(&self) -> f64 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[16..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_test1(&mut self, x: f64) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f64 as *const u8, self.0[16..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn test2(&self) -> Color { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[24..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_test2(&mut self, x: Color) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const Color as *const u8, self.0[24..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/my_game/example_2/monster_generated.rs b/tests/monster_test/my_game/example_2/monster_generated.rs index b1defc42ae7..1b9817cf5cd 100644 --- a/tests/monster_test/my_game/example_2/monster_generated.rs +++ b/tests/monster_test/my_game/example_2/monster_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -49,7 +52,6 @@ impl flatbuffers::Verifiable for Monster<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .finish(); Ok(()) @@ -84,8 +86,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl std::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Monster"); ds.finish() } diff --git a/tests/monster_test/my_game/in_parent_namespace_generated.rs b/tests/monster_test/my_game/in_parent_namespace_generated.rs index 84d25bf6177..40da52fccc6 100644 --- a/tests/monster_test/my_game/in_parent_namespace_generated.rs +++ b/tests/monster_test/my_game/in_parent_namespace_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum InParentNamespaceOffset {} #[derive(Copy, Clone, PartialEq)] @@ -49,7 +52,6 @@ impl flatbuffers::Verifiable for InParentNamespace<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .finish(); Ok(()) @@ -84,8 +86,8 @@ impl<'a: 'b, 'b> InParentNamespaceBuilder<'a, 'b> { } } -impl std::fmt::Debug for InParentNamespace<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for InParentNamespace<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("InParentNamespace"); ds.finish() } diff --git a/tests/monster_test/my_game/other_name_space/from_include_generated.rs b/tests/monster_test/my_game/other_name_space/from_include_generated.rs index 048bafdb8d0..9112c751e13 100644 --- a/tests/monster_test/my_game/other_name_space/from_include_generated.rs +++ b/tests/monster_test/my_game/other_name_space/from_include_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; @@ -34,8 +37,8 @@ impl FromInclude { } } } -impl std::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for FromInclude { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -81,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for FromInclude { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i64::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/other_name_space/table_b_generated.rs b/tests/monster_test/my_game/other_name_space/table_b_generated.rs index d7aee6407b1..7c9a8fdbdee 100644 --- a/tests/monster_test/my_game/other_name_space/table_b_generated.rs +++ b/tests/monster_test/my_game/other_name_space/table_b_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for TableB<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("a", Self::VT_A, false)? .finish(); @@ -102,8 +104,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 fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/monster_test/my_game/other_name_space/unused_generated.rs b/tests/monster_test/my_game/other_name_space/unused_generated.rs index f3fb099ff61..cd9a96d4c97 100644 --- a/tests/monster_test/my_game/other_name_space/unused_generated.rs +++ b/tests/monster_test/my_game/other_name_space/unused_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -13,8 +16,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 fmt::Debug for Unused { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -42,7 +45,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()) + slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -53,7 +56,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()) + slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -64,7 +67,6 @@ impl<'a> flatbuffers::Verifiable for Unused { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -83,24 +85,24 @@ impl<'a> Unused { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/table_a_generated.rs b/tests/monster_test/table_a_generated.rs index 89c6a5fc80c..91274b1efdf 100644 --- a/tests/monster_test/table_a_generated.rs +++ b/tests/monster_test/table_a_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for TableA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("b", Self::VT_B, false)? .finish(); @@ -102,8 +104,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 fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/more_defaults/abc_generated.rs b/tests/more_defaults/abc_generated.rs index 8622d9ba187..cb4e19f7098 100644 --- a/tests/more_defaults/abc_generated.rs +++ b/tests/more_defaults/abc_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ABC: i32 = 0; @@ -42,8 +45,8 @@ impl ABC { } } } -impl std::fmt::Debug for ABC { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for ABC { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -89,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for ABC { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i32::run_verifier(v, pos) } } diff --git a/tests/more_defaults/more_defaults_generated.rs b/tests/more_defaults/more_defaults_generated.rs index 87f6ba36a83..69612aa2b5e 100644 --- a/tests/more_defaults/more_defaults_generated.rs +++ b/tests/more_defaults/more_defaults_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MoreDefaultsOffset {} #[derive(Copy, Clone, PartialEq)] @@ -116,7 +119,6 @@ impl flatbuffers::Verifiable for MoreDefaults<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>>("ints", Self::VT_INTS, false)? .visit_field::>>("floats", Self::VT_FLOATS, false)? @@ -193,8 +195,8 @@ impl<'a: 'b, 'b> MoreDefaultsBuilder<'a, 'b> { } } -impl std::fmt::Debug for MoreDefaults<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for MoreDefaults<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("MoreDefaults"); ds.field("ints", &self.ints()); ds.field("floats", &self.floats()); diff --git a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs index b6366385a29..7b6f3ded12b 100644 --- a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ENUM_IN_NESTED_NS: i8 = 0; @@ -42,8 +45,8 @@ impl EnumInNestedNS { } } } -impl std::fmt::Debug for EnumInNestedNS { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for EnumInNestedNS { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -89,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for EnumInNestedNS { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs index 0fbd86e05f6..73850aad3c4 100644 --- a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct StructInNestedNS, aligned to 4 #[repr(transparent)] @@ -13,8 +16,8 @@ impl Default for StructInNestedNS { Self([0; 8]) } } -impl std::fmt::Debug for StructInNestedNS { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for StructInNestedNS { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("StructInNestedNS") .field("a", &self.a()) .field("b", &self.b()) @@ -43,7 +46,7 @@ impl<'b> flatbuffers::Push for StructInNestedNS { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size()) + slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -54,7 +57,7 @@ impl<'b> flatbuffers::Push for &'b StructInNestedNS { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size()) + slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -65,7 +68,6 @@ impl<'a> flatbuffers::Verifiable for StructInNestedNS { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -86,47 +88,47 @@ impl<'a> StructInNestedNS { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn b(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_b(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs index 575a855686d..588bba8c545 100644 --- a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableInNestedNSOffset {} #[derive(Copy, Clone, PartialEq)] @@ -58,7 +61,6 @@ impl flatbuffers::Verifiable for TableInNestedNS<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("foo", Self::VT_FOO, false)? .finish(); @@ -100,8 +102,8 @@ impl<'a: 'b, 'b> TableInNestedNSBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableInNestedNS<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for TableInNestedNS<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableInNestedNS"); ds.field("foo", &self.foo()); ds.finish() diff --git a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs index 8d650a5139c..4e2ab0600b1 100644 --- a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_UNION_IN_NESTED_NS: u8 = 0; @@ -38,8 +41,8 @@ impl UnionInNestedNS { } } } -impl std::fmt::Debug for UnionInNestedNS { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for UnionInNestedNS { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -85,7 +88,6 @@ impl<'a> flatbuffers::Verifiable for UnionInNestedNS { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -121,7 +123,7 @@ impl UnionInNestedNST { /// If the union variant matches, return the owned TableInNestedNST, setting the union to NONE. pub fn take_table_in_nested_ns(&mut self) -> Option> { if let Self::TableInNestedNS(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::TableInNestedNS(w) = v { Some(w) } else { diff --git a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs index 385e8dd7c80..c6b84c9de49 100644 --- a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs +++ b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum SecondTableInAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -60,7 +63,6 @@ impl flatbuffers::Verifiable for SecondTableInA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("refer_to_c", Self::VT_REFER_TO_C, false)? .finish(); @@ -102,8 +104,8 @@ impl<'a: 'b, 'b> SecondTableInABuilder<'a, 'b> { } } -impl std::fmt::Debug for SecondTableInA<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for SecondTableInA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("SecondTableInA"); ds.field("refer_to_c", &self.refer_to_c()); ds.finish() diff --git a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs index 018e526a928..a2a7c8de7ce 100644 --- a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs +++ b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableInFirstNSOffset {} #[derive(Copy, Clone, PartialEq)] @@ -110,7 +113,6 @@ impl flatbuffers::Verifiable for TableInFirstNS<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("foo_table", Self::VT_FOO_TABLE, false)? .visit_field::("foo_enum", Self::VT_FOO_ENUM, false)? @@ -184,8 +186,8 @@ impl<'a: 'b, 'b> TableInFirstNSBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableInFirstNS<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for TableInFirstNS<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableInFirstNS"); ds.field("foo_table", &self.foo_table()); ds.field("foo_enum", &self.foo_enum()); diff --git a/tests/namespace_test/namespace_c/table_in_c_generated.rs b/tests/namespace_test/namespace_c/table_in_c_generated.rs index 5a1bdc9a683..2c11f730659 100644 --- a/tests/namespace_test/namespace_c/table_in_c_generated.rs +++ b/tests/namespace_test/namespace_c/table_in_c_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableInCOffset {} #[derive(Copy, Clone, PartialEq)] @@ -70,7 +73,6 @@ impl flatbuffers::Verifiable for TableInC<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("refer_to_a1", Self::VT_REFER_TO_A1, false)? .visit_field::>("refer_to_a2", Self::VT_REFER_TO_A2, false)? @@ -119,8 +121,8 @@ impl<'a: 'b, 'b> TableInCBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableInC<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for TableInC<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableInC"); ds.field("refer_to_a1", &self.refer_to_a1()); ds.field("refer_to_a2", &self.refer_to_a2()); diff --git a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs index 226e9ecefd0..62c4e4d64b8 100644 --- a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs +++ b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_OPTIONAL_BYTE: i8 = 0; @@ -42,8 +45,8 @@ impl OptionalByte { } } } -impl std::fmt::Debug for OptionalByte { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for OptionalByte { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -89,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for OptionalByte { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs index 4b610f48763..37186f577f1 100644 --- a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs +++ b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs @@ -1,8 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify +extern crate alloc; +extern crate core; extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::alloc::{boxed::Box, vec::Vec}; +use self::alloc::string::{String, ToString as _}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum ScalarStuffOffset {} #[derive(Copy, Clone, PartialEq)] @@ -338,7 +341,6 @@ impl flatbuffers::Verifiable for ScalarStuff<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("just_i8", Self::VT_JUST_I8, false)? .visit_field::("maybe_i8", Self::VT_MAYBE_I8, false)? @@ -625,8 +627,8 @@ impl<'a: 'b, 'b> ScalarStuffBuilder<'a, 'b> { } } -impl std::fmt::Debug for ScalarStuff<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for ScalarStuff<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("ScalarStuff"); ds.field("just_i8", &self.just_i8()); ds.field("maybe_i8", &self.maybe_i8()); diff --git a/tests/phpUnionVectorTest.sh b/tests/phpUnionVectorTest.sh index a6c3f264401..d40ac66687b 100755 --- a/tests/phpUnionVectorTest.sh +++ b/tests/phpUnionVectorTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/tests/rust_usage_test/Cargo.toml b/tests/rust_usage_test/Cargo.toml index 22b259084eb..9a09ab94bb4 100644 --- a/tests/rust_usage_test/Cargo.toml +++ b/tests/rust_usage_test/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Robert Winslow ", "FlatBuffers Maintainers"] [dependencies] -flatbuffers = { path = "../../rust/flatbuffers" } +flatbuffers = { path = "../../rust/flatbuffers", default_features = false } flexbuffers = { path = "../../rust/flexbuffers" } serde_derive = "1.0" serde = "1.0" @@ -49,3 +49,7 @@ array-init = "2.0" # setup for bencher name = "benchmarks" harness = false + +[features] +default = ["std"] +std = ["flatbuffers/std"] diff --git a/tests/rust_usage_test/tests/no_std_test.rs b/tests/rust_usage_test/tests/no_std_test.rs new file mode 100644 index 00000000000..ca91314ad5f --- /dev/null +++ b/tests/rust_usage_test/tests/no_std_test.rs @@ -0,0 +1,60 @@ +#![no_std] + +extern crate flatbuffers; + +#[allow(dead_code, unused_imports)] +#[path = "../../monster_test/mod.rs"] +mod monster_test_generated; +pub use monster_test_generated::my_game; + +static MONSTER_DATA: &[u8] = include_bytes!("../../monsterdata_test.mon"); + +// Note: Copied from `bin/monster_example.rs` +#[test] +fn no_std_example_data() { + let monster = my_game::example::root_as_monster(MONSTER_DATA).unwrap(); + + assert_eq!(monster.hp(), 80); + assert_eq!(monster.mana(), 150); + assert_eq!(monster.name(), "MyMonster"); +} + +// Note: the rest was copied from the `roundtrip_generated_code` module in +// `tests/integration_test.rs`. Really just making sure that everything compiles +// here, the behavior has already been tested. + +fn build_mon<'a, 'b>( + builder: &'a mut flatbuffers::FlatBufferBuilder, + args: &'b my_game::example::MonsterArgs, +) -> my_game::example::Monster<'a> { + let mon = my_game::example::Monster::create(builder, &args); + my_game::example::finish_monster_buffer(builder, mon); + my_game::example::root_as_monster(builder.finished_data()).unwrap() +} + +#[test] +fn vector_of_struct_store_with_type_inference() { + let mut b = flatbuffers::FlatBufferBuilder::new(); + let v = b.create_vector(&[ + my_game::example::Test::new(127, -128), + my_game::example::Test::new(3, 123), + my_game::example::Test::new(100, 101), + ]); + let name = b.create_string("foo"); + let m = build_mon( + &mut b, + &my_game::example::MonsterArgs { + name: Some(name), + test4: Some(v), + ..Default::default() + }, + ); + assert_eq!( + m.test4().unwrap(), + &[ + my_game::example::Test::new(127, -128), + my_game::example::Test::new(3, 123), + my_game::example::Test::new(100, 101) + ][..] + ); +}