Skip to content

Commit

Permalink
refactor(de): Remove unnecessary &mut (toml-rs#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
epage authored Sep 9, 2021
1 parent 0908e81 commit eac293d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/easy/de/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'de> serde::de::SeqAccess<'de> for ArraySeqAccess {
{
match self.iter.next() {
Some(v) => seed
.deserialize(&mut crate::easy::de::ItemDeserializer::new(v))
.deserialize(crate::easy::de::ItemDeserializer::new(v))
.map(Some),
None => Ok(None),
}
Expand Down
2 changes: 1 addition & 1 deletion src/easy/de/inline_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'de> serde::de::MapAccess<'de> for InlineTableMapAccess {
V: serde::de::DeserializeSeed<'de>,
{
match self.value.take() {
Some(v) => seed.deserialize(&mut crate::easy::de::ItemDeserializer::new(v)),
Some(v) => seed.deserialize(crate::easy::de::ItemDeserializer::new(v)),
None => {
panic!("no more values in next_value_seed, internal error in ValueDeserializer")
}
Expand Down
6 changes: 2 additions & 4 deletions src/easy/de/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ impl ItemDeserializer {
}
}

impl<'de, 'a> serde::Deserializer<'de> for &'a mut ItemDeserializer {
impl<'de, 'a> serde::Deserializer<'de> for ItemDeserializer {
type Error = Error;

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: serde::de::Visitor<'de>,
{
let mut input = Default::default();
std::mem::swap(&mut input, &mut self.input);
match input {
match self.input {
crate::Item::None => visitor.visit_none(),
crate::Item::Value(v) => {
crate::easy::de::ValueDeserializer::new(v).deserialize_any(visitor)
Expand Down
10 changes: 4 additions & 6 deletions src/easy/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub fn from_document<T>(d: crate::Document) -> Result<T, Error>
where
T: Deserialize<'static>,
{
let mut deserializer = Deserializer::new(d);
T::deserialize(&mut deserializer)
let deserializer = Deserializer::new(d);
T::deserialize(deserializer)
}

/// Deserialization implementation for TOML.
Expand All @@ -103,16 +103,14 @@ impl Deserializer {
}
}

impl<'de, 'a> serde::Deserializer<'de> for &'a mut Deserializer {
impl<'de, 'a> serde::Deserializer<'de> for Deserializer {
type Error = Error;

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: serde::de::Visitor<'de>,
{
let mut input = Default::default();
std::mem::swap(&mut input, &mut self.input.root);
ItemDeserializer::new(input).deserialize_any(visitor)
ItemDeserializer::new(self.input.root).deserialize_any(visitor)
}

// `None` is interpreted as a missing field so be sure to implement `Some`
Expand Down
2 changes: 1 addition & 1 deletion src/easy/de/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'de> serde::de::MapAccess<'de> for TableMapAccess {
V: serde::de::DeserializeSeed<'de>,
{
match self.value.take() {
Some(v) => seed.deserialize(&mut crate::easy::de::ItemDeserializer::new(v)),
Some(v) => seed.deserialize(crate::easy::de::ItemDeserializer::new(v)),
None => {
panic!("no more values in next_value_seed, internal error in ValueDeserializer")
}
Expand Down
6 changes: 2 additions & 4 deletions src/easy/de/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ impl ValueDeserializer {
}
}

impl<'de, 'a> serde::Deserializer<'de> for &'a mut ValueDeserializer {
impl<'de, 'a> serde::Deserializer<'de> for ValueDeserializer {
type Error = Error;

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: serde::de::Visitor<'de>,
{
let mut input: crate::Value = 0.into();
std::mem::swap(&mut input, &mut self.input);
match input {
match self.input {
crate::Value::String(v) => visitor.visit_string(v.into_value()),
crate::Value::Integer(v) => visitor.visit_i64(v.into_value()),
crate::Value::Float(v) => visitor.visit_f64(v.into_value()),
Expand Down

0 comments on commit eac293d

Please sign in to comment.