mirror of https://git.sr.ht/~stygianentity/bincode
Merge pull request #281 from jstarry/fix-emscripten-builds
Fix emscripten build failures due to lack of i128 support
This commit is contained in:
commit
04cc5ba85f
11
Cargo.toml
11
Cargo.toml
|
|
@ -11,7 +11,6 @@ documentation = "https://docs.rs/bincode"
|
||||||
readme = "./readme.md"
|
readme = "./readme.md"
|
||||||
categories = ["encoding", "network-programming"]
|
categories = ["encoding", "network-programming"]
|
||||||
keywords = ["binary", "encode", "decode", "serialize", "deserialize"]
|
keywords = ["binary", "encode", "decode", "serialize", "deserialize"]
|
||||||
build = "build.rs"
|
|
||||||
|
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "A binary serialization / deserialization strategy that uses Serde for transforming structs into bytes and vice versa!"
|
description = "A binary serialization / deserialization strategy that uses Serde for transforming structs into bytes and vice versa!"
|
||||||
|
|
@ -24,13 +23,11 @@ serde = "1.0.63"
|
||||||
serde_bytes = "0.11"
|
serde_bytes = "0.11"
|
||||||
serde_derive = "1.0.27"
|
serde_derive = "1.0.27"
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
autocfg = "0.1.2"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# This feature is no longer used and is DEPRECATED. This crate now
|
# This feature is no longer used and is DEPRECATED. This crate relies on the
|
||||||
# automatically enables i128 support for Rust compilers that support it. The
|
# serde `serde_if_integer128` macro to enable i128 support for Rust compilers
|
||||||
# feature will be removed if and when a new major version is released.
|
# and targets that support it. The feature will be removed if and when a new
|
||||||
|
# major version is released.
|
||||||
i128 = []
|
i128 = []
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
|
|
|
||||||
8
build.rs
8
build.rs
|
|
@ -1,8 +0,0 @@
|
||||||
extern crate autocfg;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
autocfg::rerun_path(file!());
|
|
||||||
|
|
||||||
let ac = autocfg::new();
|
|
||||||
ac.emit_has_type("i128");
|
|
||||||
}
|
|
||||||
|
|
@ -108,30 +108,9 @@ where
|
||||||
impl_nums!(f32, deserialize_f32, visit_f32, read_f32);
|
impl_nums!(f32, deserialize_f32, visit_f32, read_f32);
|
||||||
impl_nums!(f64, deserialize_f64, visit_f64, read_f64);
|
impl_nums!(f64, deserialize_f64, visit_f64, read_f64);
|
||||||
|
|
||||||
#[cfg(has_i128)]
|
|
||||||
impl_nums!(u128, deserialize_u128, visit_u128, read_u128);
|
|
||||||
|
|
||||||
#[cfg(has_i128)]
|
|
||||||
impl_nums!(i128, deserialize_i128, visit_i128, read_i128);
|
|
||||||
|
|
||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
#[cfg(not(has_i128))]
|
impl_nums!(u128, deserialize_u128, visit_u128, read_u128);
|
||||||
fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value>
|
impl_nums!(i128, deserialize_i128, visit_i128, read_i128);
|
||||||
where
|
|
||||||
V: serde::de::Visitor<'de>
|
|
||||||
{
|
|
||||||
let _ = visitor;
|
|
||||||
Err(DeError::custom("u128 is not supported. Use Rustc ≥ 1.26."))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(has_i128))]
|
|
||||||
fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value>
|
|
||||||
where
|
|
||||||
V: serde::de::Visitor<'de>
|
|
||||||
{
|
|
||||||
let _ = visitor;
|
|
||||||
Err(DeError::custom("i128 is not supported. Use Rustc ≥ 1.26."))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
//! ### 128bit numbers
|
//! ### 128bit numbers
|
||||||
//!
|
//!
|
||||||
//! Support for `i128` and `u128` is automatically enabled on Rust toolchains
|
//! Support for `i128` and `u128` is automatically enabled on Rust toolchains
|
||||||
//! greater than or equal to `1.26.0`.
|
//! greater than or equal to `1.26.0` and disabled for targets which do not support it
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/bincode/1.2.0")]
|
#![doc(html_root_url = "https://docs.rs/bincode/1.2.0")]
|
||||||
#![crate_name = "bincode"]
|
#![crate_name = "bincode"]
|
||||||
|
|
|
||||||
|
|
@ -88,31 +88,13 @@ impl<'a, W: Write, O: Options> serde::Serializer for &'a mut Serializer<W, O> {
|
||||||
self.writer.write_i64::<O::Endian>(v).map_err(Into::into)
|
self.writer.write_i64::<O::Endian>(v).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(has_i128)]
|
|
||||||
fn serialize_u128(self, v: u128) -> Result<()> {
|
|
||||||
self.writer.write_u128::<O::Endian>(v).map_err(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(has_i128)]
|
|
||||||
fn serialize_i128(self, v: i128) -> Result<()> {
|
|
||||||
self.writer.write_i128::<O::Endian>(v).map_err(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
#[cfg(not(has_i128))]
|
|
||||||
fn serialize_u128(self, v: u128) -> Result<()> {
|
fn serialize_u128(self, v: u128) -> Result<()> {
|
||||||
use serde::ser::Error;
|
self.writer.write_u128::<O::Endian>(v).map_err(Into::into)
|
||||||
|
|
||||||
let _ = v;
|
|
||||||
Err(Error::custom("u128 is not supported. Use Rustc ≥ 1.26."))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(has_i128))]
|
|
||||||
fn serialize_i128(self, v: i128) -> Result<()> {
|
fn serialize_i128(self, v: i128) -> Result<()> {
|
||||||
use serde::ser::Error;
|
self.writer.write_i128::<O::Endian>(v).map_err(Into::into)
|
||||||
|
|
||||||
let _ = v;
|
|
||||||
Err(Error::custom("i128 is not supported. Use Rustc ≥ 1.26."))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ extern crate serde_derive;
|
||||||
|
|
||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_bytes;
|
extern crate serde_bytes;
|
||||||
|
|
||||||
|
|
@ -72,18 +73,19 @@ fn test_numbers() {
|
||||||
the_same(5f64);
|
the_same(5f64);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(has_i128)]
|
serde_if_integer128! {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_numbers_128bit() {
|
fn test_numbers_128bit() {
|
||||||
// unsigned positive
|
// unsigned positive
|
||||||
the_same(5u128);
|
the_same(5u128);
|
||||||
the_same(u128::max_value());
|
the_same(u128::max_value());
|
||||||
// signed positive
|
// signed positive
|
||||||
the_same(5i128);
|
the_same(5i128);
|
||||||
the_same(i128::max_value());
|
the_same(i128::max_value());
|
||||||
// signed negative
|
// signed negative
|
||||||
the_same(-5i128);
|
the_same(-5i128);
|
||||||
the_same(i128::min_value());
|
the_same(i128::min_value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue