Skip to content

Commit

Permalink
upgrade to value-bag 1.0.0-alpha.9 and remove by-value 128bit int con…
Browse files Browse the repository at this point in the history
…versions
  • Loading branch information
KodrAus committed Apr 20, 2022
1 parent 4249b56 commit 91d741f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ kv_unstable_serde = ["kv_unstable_std", "value-bag/serde", "serde"]
cfg-if = "1.0"
serde = { version = "1.0", optional = true, default-features = false }
sval = { version = "=1.0.0-alpha.5", optional = true, default-features = false }
value-bag = { version = "=1.0.0-alpha.8", optional = true, default-features = false }
value-bag = { version = "=1.0.0-alpha.9", optional = true, default-features = false }

[dev-dependencies]
rustversion = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_test = "1.0"
sval = { version = "=1.0.0-alpha.5", features = ["derive"] }
value-bag = { version = "=1.0.0-alpha.8", features = ["test"] }
value-bag = { version = "=1.0.0-alpha.9", features = ["test"] }
58 changes: 53 additions & 5 deletions src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,60 @@ impl ToValue for str {
}
}

impl ToValue for u128 {
fn to_value(&self) -> Value {
Value::from(self)
}
}

impl ToValue for i128 {
fn to_value(&self) -> Value {
Value::from(self)
}
}

impl ToValue for std::num::NonZeroU128 {
fn to_value(&self) -> Value {
Value::from(self)
}
}

impl ToValue for std::num::NonZeroI128 {
fn to_value(&self) -> Value {
Value::from(self)
}
}

impl<'v> From<&'v str> for Value<'v> {
fn from(value: &'v str) -> Self {
Value::from_value_bag(value)
}
}

impl<'v> From<&'v u128> for Value<'v> {
fn from(value: &'v u128) -> Self {
Value::from_value_bag(value)
}
}

impl<'v> From<&'v i128> for Value<'v> {
fn from(value: &'v i128) -> Self {
Value::from_value_bag(value)
}
}

impl<'v> From<&'v std::num::NonZeroU128> for Value<'v> {
fn from(v: &'v std::num::NonZeroU128) -> Value<'v> {
Value::from_value_bag(unsafe { std::mem::transmute::<&std::num::NonZeroU128, &u128>(v) })
}
}

impl<'v> From<&'v std::num::NonZeroI128> for Value<'v> {
fn from(v: &'v std::num::NonZeroI128) -> Value<'v> {
Value::from_value_bag(unsafe { std::mem::transmute::<&std::num::NonZeroI128, &i128>(v) })
}
}

impl ToValue for () {
fn to_value(&self) -> Value {
Value::from_value_bag(())
Expand Down Expand Up @@ -515,13 +563,13 @@ macro_rules! impl_value_to_primitive {
}

impl_to_value_primitive![
usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, f32, f64, char, bool,
usize, u8, u16, u32, u64, isize, i8, i16, i32, i64, f32, f64, char, bool,
];

#[rustfmt::skip]
impl_to_value_nonzero_primitive![
NonZeroUsize, NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128,
NonZeroIsize, NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128,
NonZeroUsize, NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64,
NonZeroIsize, NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64,
];

impl_value_to_primitive![
Expand Down Expand Up @@ -617,12 +665,12 @@ pub trait Visit<'v> {

/// Visit a big unsigned integer.
fn visit_u128(&mut self, value: u128) -> Result<(), Error> {
self.visit_any(value.into())
self.visit_any((&value).into())
}

/// Visit a big signed integer.
fn visit_i128(&mut self, value: i128) -> Result<(), Error> {
self.visit_any(value.into())
self.visit_any((&value).into())
}

/// Visit a floating point.
Expand Down

0 comments on commit 91d741f

Please sign in to comment.