diff --git a/Cargo.toml b/Cargo.toml index 44fc33b..e4ff9c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,12 +16,12 @@ exclude = [".gitignore", ".github"] [dependencies] serde = "1.0, <= 1.0.156" -magnus = "0.5" -rb-sys = "0.9, <= 0.9.71" -rb-sys-build = "0.9, <= 0.9.71" +magnus = "0.6.2" +rb-sys = "0.9, <= 0.9.81" +rb-sys-build = "0.9, <= 0.9.81" tap = "1.0" [dev-dependencies] serde = { version = "1.0", features = ["derive"] } serde_bytes = "0.11" -magnus = { version = "0.5", features = ["embed"] } +magnus = { version = "0.6.2", features = ["embed"] } diff --git a/src/de/deserializer.rs b/src/de/deserializer.rs index 590f0bf..5e44625 100644 --- a/src/de/deserializer.rs +++ b/src/de/deserializer.rs @@ -1,8 +1,9 @@ use magnus::{ exception, - value::{Qfalse, Qtrue}, + value::{qnil, Qfalse, Qtrue, ReprValue}, Fixnum, Float, RArray, RBignum, RHash, RString, Symbol, Value, }; + use serde::forward_to_deserialize_any; use super::{ArrayDeserializer, EnumDeserializer, HashDeserializer}; @@ -124,7 +125,7 @@ impl<'i> serde::Deserializer<'i> for Deserializer { if let Some(variant) = RString::from_value(self.value) { return visitor.visit_enum(EnumDeserializer::new( variant.to_string()?, - Value::default(), + qnil().as_value(), )); } @@ -132,7 +133,7 @@ impl<'i> serde::Deserializer<'i> for Deserializer { if hash.len() == 1 { let keys: RArray = hash.funcall("keys", ())?; let key: String = keys.entry(0)?; - let value = hash.get(key.as_str()).unwrap_or_default(); + let value = hash.get(key.as_str()).unwrap_or_else(|| qnil().as_value()); return visitor.visit_enum(EnumDeserializer::new(key, value)); } else { diff --git a/src/de/hash_deserializer.rs b/src/de/hash_deserializer.rs index be90b70..d8ac607 100644 --- a/src/de/hash_deserializer.rs +++ b/src/de/hash_deserializer.rs @@ -1,6 +1,6 @@ use super::{array_enumerator::ArrayEnumerator, Deserializer}; use crate::error::Error; -use magnus::{exception, RHash}; +use magnus::{exception, value::ReprValue, RHash}; use serde::de::{DeserializeSeed, MapAccess}; use std::iter::Peekable; diff --git a/src/de/variant_deserializer.rs b/src/de/variant_deserializer.rs index c690de0..d2631d0 100644 --- a/src/de/variant_deserializer.rs +++ b/src/de/variant_deserializer.rs @@ -1,6 +1,6 @@ use super::{ArrayDeserializer, Deserializer, HashDeserializer}; use crate::error::Error; -use magnus::{RArray, RHash, Value}; +use magnus::{value::ReprValue, RArray, RHash, Value}; use serde::de::{DeserializeSeed, Unexpected, VariantAccess}; pub struct VariantDeserializer { diff --git a/src/ser/enums.rs b/src/ser/enums.rs index 469d0bb..106adcc 100644 --- a/src/ser/enums.rs +++ b/src/ser/enums.rs @@ -1,12 +1,11 @@ use crate::error::Error; -use magnus::{RHash, Value}; -use std::ops::Deref; +use magnus::{IntoValue, RHash, Value}; pub fn nest(variant: &'static str, data: Data) -> Result where - Data: Deref, + Data: IntoValue, { let hash = RHash::new(); - hash.aset(variant, *data)?; - Ok(*hash) + hash.aset(variant, data)?; + Ok(hash.into_value()) } diff --git a/src/ser/map_serializer.rs b/src/ser/map_serializer.rs index b395382..17cebaa 100644 --- a/src/ser/map_serializer.rs +++ b/src/ser/map_serializer.rs @@ -1,6 +1,9 @@ use super::Serializer; use crate::error::Error; -use magnus::{RHash, Value}; +use magnus::{ + value::{qnil, ReprValue}, + IntoValue, RHash, Value, +}; use serde::{ser::SerializeMap, Serialize}; pub struct MapSerializer { @@ -12,7 +15,7 @@ impl MapSerializer { pub fn new(hash: RHash) -> MapSerializer { MapSerializer { hash, - key: Value::default(), + key: qnil().as_value(), } } } @@ -39,6 +42,6 @@ impl SerializeMap for MapSerializer { } fn end(self) -> Result { - Ok(*self.hash) + Ok(self.hash.into_value()) } } diff --git a/src/ser/mod.rs b/src/ser/mod.rs index b3ff2cb..3e22732 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -400,8 +400,5 @@ where Input: Serialize + ?Sized, Output: TryConvert, { - input - .serialize(Serializer)? - .try_convert() - .map_err(Into::into) + TryConvert::try_convert(input.serialize(Serializer)?).map_err(Into::into) } diff --git a/src/ser/seq_serializer.rs b/src/ser/seq_serializer.rs index 03d2a48..5ef9d1c 100644 --- a/src/ser/seq_serializer.rs +++ b/src/ser/seq_serializer.rs @@ -1,6 +1,6 @@ use super::Serializer; use crate::error::Error; -use magnus::{RArray, Value}; +use magnus::{IntoValue, RArray, Value}; use serde::{ ser::{SerializeSeq, SerializeTuple, SerializeTupleStruct}, Serialize, @@ -30,7 +30,7 @@ impl SerializeSeq for SeqSerializer { } fn end(self) -> Result { - Ok(*self.array) + Ok(self.array.into_value()) } } diff --git a/src/ser/serializer.rs b/src/ser/serializer.rs index 6338d21..3cbeadb 100644 --- a/src/ser/serializer.rs +++ b/src/ser/serializer.rs @@ -1,4 +1,4 @@ -use magnus::{RArray, RHash, RString, Value}; +use magnus::{IntoValue, RArray, RHash, RString, Value}; use serde::Serialize; use super::{ @@ -22,63 +22,63 @@ impl serde::Serializer for Serializer { type SerializeStructVariant = StructVariantSerializer; fn serialize_bool(self, value: bool) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_i8(self, value: i8) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_i16(self, value: i16) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_i32(self, value: i32) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_i64(self, value: i64) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_u8(self, value: u8) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_u16(self, value: u16) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_u32(self, value: u32) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_u64(self, value: u64) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_f32(self, value: f32) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_f64(self, value: f64) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_char(self, value: char) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_str(self, value: &str) -> Result { - Ok(value.into()) + Ok(value.into_value()) } fn serialize_bytes(self, value: &[u8]) -> Result { - Ok(*RString::from_slice(value)) + Ok(RString::from_slice(value).into_value()) } fn serialize_none(self) -> Result { - Ok(().into()) + Ok(().into_value()) } fn serialize_some(self, value: &Value) -> Result @@ -89,11 +89,11 @@ impl serde::Serializer for Serializer { } fn serialize_unit(self) -> Result { - Ok(().into()) + Ok(().into_value()) } fn serialize_unit_struct(self, _name: &'static str) -> Result { - Ok(().into()) + Ok(().into_value()) } fn serialize_unit_variant( @@ -102,7 +102,7 @@ impl serde::Serializer for Serializer { _index: u32, variant: &'static str, ) -> Result { - Ok(variant.into()) + Ok(variant.into_value()) } fn serialize_newtype_struct( @@ -126,7 +126,7 @@ impl serde::Serializer for Serializer { where Value: Serialize + ?Sized, { - nest(variant, &value.serialize(self)?) + nest(variant, value.serialize(self)?) } fn serialize_seq(self, len: Option) -> Result { diff --git a/src/ser/struct_serializer.rs b/src/ser/struct_serializer.rs index 2aaf126..9fddaee 100644 --- a/src/ser/struct_serializer.rs +++ b/src/ser/struct_serializer.rs @@ -1,6 +1,6 @@ use super::Serializer; use crate::error::Error; -use magnus::{RHash, Symbol, Value}; +use magnus::{IntoValue, RHash, Symbol, Value}; use serde::{ser::SerializeStruct, Serialize}; pub struct StructSerializer { @@ -31,6 +31,6 @@ impl SerializeStruct for StructSerializer { } fn end(self) -> Result { - Ok(*self.hash) + Ok(self.hash.into_value()) } }