Skip to content

Commit

Permalink
Update to latest Magnus
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilm committed Oct 18, 2023
1 parent 8ab22e4 commit 943c4fb
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
7 changes: 4 additions & 3 deletions src/de/deserializer.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -124,15 +125,15 @@ 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(),
));
}

if let Some(hash) = RHash::from_value(self.value) {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/de/hash_deserializer.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/de/variant_deserializer.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions src/ser/enums.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::error::Error;
use magnus::{RHash, Value};
use std::ops::Deref;
use magnus::{IntoValue, RHash, Value};

pub fn nest<Data>(variant: &'static str, data: Data) -> Result<Value, Error>
where
Data: Deref<Target = Value>,
Data: IntoValue,
{
let hash = RHash::new();
hash.aset(variant, *data)?;
Ok(*hash)
hash.aset(variant, data)?;
Ok(hash.into_value())
}
9 changes: 6 additions & 3 deletions src/ser/map_serializer.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,7 +15,7 @@ impl MapSerializer {
pub fn new(hash: RHash) -> MapSerializer {
MapSerializer {
hash,
key: Value::default(),
key: qnil().as_value(),
}
}
}
Expand All @@ -39,6 +42,6 @@ impl SerializeMap for MapSerializer {
}

fn end(self) -> Result<Self::Ok, Self::Error> {
Ok(*self.hash)
Ok(self.hash.into_value())
}
}
5 changes: 1 addition & 4 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions src/ser/seq_serializer.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -30,7 +30,7 @@ impl SerializeSeq for SeqSerializer {
}

fn end(self) -> Result<Self::Ok, self::Error> {
Ok(*self.array)
Ok(self.array.into_value())
}
}

Expand Down
40 changes: 20 additions & 20 deletions src/ser/serializer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use magnus::{RArray, RHash, RString, Value};
use magnus::{IntoValue, RArray, RHash, RString, Value};
use serde::Serialize;

use super::{
Expand All @@ -22,63 +22,63 @@ impl serde::Serializer for Serializer {
type SerializeStructVariant = StructVariantSerializer;

fn serialize_bool(self, value: bool) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_i8(self, value: i8) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_i16(self, value: i16) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_i32(self, value: i32) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_i64(self, value: i64) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_u8(self, value: u8) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_u16(self, value: u16) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_u32(self, value: u32) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_u64(self, value: u64) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_f32(self, value: f32) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_f64(self, value: f64) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_char(self, value: char) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_str(self, value: &str) -> Result<Self::Ok, Self::Error> {
Ok(value.into())
Ok(value.into_value())
}

fn serialize_bytes(self, value: &[u8]) -> Result<Self::Ok, Self::Error> {
Ok(*RString::from_slice(value))
Ok(RString::from_slice(value).into_value())
}

fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
Ok(().into())
Ok(().into_value())
}

fn serialize_some<Value>(self, value: &Value) -> Result<Self::Ok, Self::Error>
Expand All @@ -89,11 +89,11 @@ impl serde::Serializer for Serializer {
}

fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
Ok(().into())
Ok(().into_value())
}

fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
Ok(().into())
Ok(().into_value())
}

fn serialize_unit_variant(
Expand All @@ -102,7 +102,7 @@ impl serde::Serializer for Serializer {
_index: u32,
variant: &'static str,
) -> Result<Self::Ok, Self::Error> {
Ok(variant.into())
Ok(variant.into_value())
}

fn serialize_newtype_struct<Value>(
Expand All @@ -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<usize>) -> Result<Self::SerializeSeq, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions src/ser/struct_serializer.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -31,6 +31,6 @@ impl SerializeStruct for StructSerializer {
}

fn end(self) -> Result<Self::Ok, Self::Error> {
Ok(*self.hash)
Ok(self.hash.into_value())
}
}

0 comments on commit 943c4fb

Please sign in to comment.