forked from BigfootDev/flatbuffers
Improves Rust code generation (#8564)
* Fixes checks for serde features in flexbuffers crate * Removes unused MapReaderIndexer use statement * Fixes warning about nightly cfg usage Enabling a cfg attribute through cargo::rustc-cfg in build.rs should be coupled with a cargo::rust-check-cfg value so that the compiler knows about the custom cfg. See: https://doc.rust-lang.org/rustc/check-cfg/cargo-specifics.html#cargorustc-check-cfg-for-buildrsbuild-script. * Migrates usage of deprecated float constants This update fixes a compiler warning from use of the old constants. Constants like EPSILON are now directly on the float primitives (e.g. f32::EPSILON) rather than in the f32 module (std::f32::EPSILON). The new constants have existed since 1.43.0, which appears to be below the MSRV for the flatbuffers crate. * Fixes incorrect key in flatbuffers Cargo.toml The old code was using package.rust, which triggered a warning about an unused key: warning: flatbuffers/rust/flatbuffers/Cargo.toml: unused manifest key: package.rust The correct key for specifying MSRV is rust-version. See: https://doc.rust-lang.org/cargo/reference/rust-version.html#rust-version. --------- Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ homepage = "https://google.github.io/flatbuffers/"
|
|||||||
repository = "https://github.com/google/flatbuffers"
|
repository = "https://github.com/google/flatbuffers"
|
||||||
keywords = ["flatbuffers", "serialization", "zero-copy"]
|
keywords = ["flatbuffers", "serialization", "zero-copy"]
|
||||||
categories = ["encoding", "data-structures", "memory-management"]
|
categories = ["encoding", "data-structures", "memory-management"]
|
||||||
rust = "1.51"
|
rust-version = "1.51"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use rustc_version::{version_meta, Channel};
|
use rustc_version::{Channel, version_meta};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let version_meta = version_meta().unwrap();
|
let version_meta = version_meta().unwrap();
|
||||||
@@ -6,6 +6,7 @@ fn main() {
|
|||||||
// To use nightly features we declare this and then we can use
|
// To use nightly features we declare this and then we can use
|
||||||
// #[cfg(nightly)]
|
// #[cfg(nightly)]
|
||||||
// for nightly only features
|
// for nightly only features
|
||||||
|
println!("cargo:rustc-check-cfg=cfg(nightly)");
|
||||||
if version_meta.channel == Channel::Nightly {
|
if version_meta.channel == Channel::Nightly {
|
||||||
println!("cargo:rustc-cfg=nightly")
|
println!("cargo:rustc-cfg=nightly")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ impl<'a> ser::Serializer for &'a mut FlexbufferSerializer {
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn is_human_readable(&self) -> bool {
|
fn is_human_readable(&self) -> bool {
|
||||||
cfg!(serialize_human_readable)
|
cfg!(feature = "serialize_human_readable")
|
||||||
}
|
}
|
||||||
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> {
|
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> {
|
||||||
self.builder.push(v);
|
self.builder.push(v);
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ impl<'de> VariantAccess<'de> for Reader<&'de [u8]> {
|
|||||||
impl<'de> Deserializer<'de> for Reader<&'de [u8]> {
|
impl<'de> Deserializer<'de> for Reader<&'de [u8]> {
|
||||||
type Error = DeserializationError;
|
type Error = DeserializationError;
|
||||||
fn is_human_readable(&self) -> bool {
|
fn is_human_readable(&self) -> bool {
|
||||||
cfg!(deserialize_human_readable)
|
cfg!(feature = "deserialize_human_readable")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ mod serialize;
|
|||||||
mod vector;
|
mod vector;
|
||||||
pub use de::DeserializationError;
|
pub use de::DeserializationError;
|
||||||
pub use iter::ReaderIterator;
|
pub use iter::ReaderIterator;
|
||||||
pub use map::{MapReader, MapReaderIndexer};
|
pub use map::MapReader;
|
||||||
pub use vector::VectorReader;
|
pub use vector::VectorReader;
|
||||||
|
|
||||||
/// All the possible errors when reading a flexbuffer.
|
/// All the possible errors when reading a flexbuffer.
|
||||||
|
|||||||
@@ -142,10 +142,10 @@ fn main() {
|
|||||||
// We know the bits should be exactly equal here but compilers may
|
// We know the bits should be exactly equal here but compilers may
|
||||||
// optimize floats in subtle ways so we're playing it safe and using
|
// optimize floats in subtle ways so we're playing it safe and using
|
||||||
// epsilon comparison
|
// epsilon comparison
|
||||||
assert!((pos.x() - 1.0f32).abs() < std::f32::EPSILON);
|
assert!((pos.x() - 1.0f32).abs() < f32::EPSILON);
|
||||||
assert!((pos.y() - 2.0f32).abs() < std::f32::EPSILON);
|
assert!((pos.y() - 2.0f32).abs() < f32::EPSILON);
|
||||||
assert!((pos.z() - 3.0f32).abs() < std::f32::EPSILON);
|
assert!((pos.z() - 3.0f32).abs() < f32::EPSILON);
|
||||||
assert!((pos.test1() - 3.0f64).abs() < std::f64::EPSILON);
|
assert!((pos.test1() - 3.0f64).abs() < f64::EPSILON);
|
||||||
assert_eq!(pos.test2(), my_game::example::Color::Green);
|
assert_eq!(pos.test2(), my_game::example::Color::Green);
|
||||||
let pos_test3 = pos.test3();
|
let pos_test3 = pos.test3();
|
||||||
assert_eq!(pos_test3.a(), 5i16);
|
assert_eq!(pos_test3.a(), 5i16);
|
||||||
|
|||||||
Reference in New Issue
Block a user