deref mut

This commit is contained in:
Robin Appelman 2023-12-19 01:06:43 +01:00
commit 31977b9340
2 changed files with 14 additions and 2 deletions

View file

@ -7,7 +7,7 @@ use serde::de::{DeserializeSeed, MapAccess};
use serde::{Deserialize, Serialize, Serializer}; use serde::{Deserialize, Serialize, Serializer};
use std::collections::hash_map; use std::collections::hash_map;
use std::collections::HashMap; use std::collections::HashMap;
use std::ops::Deref; use std::ops::{Deref, DerefMut};
/// A table of entries. /// A table of entries.
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
@ -110,6 +110,12 @@ impl Deref for Table {
} }
} }
impl DerefMut for Table {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
pub(crate) struct TableSeq { pub(crate) struct TableSeq {
iter: hash_map::IntoIter<String, Entry>, iter: hash_map::IntoIter<String, Entry>,
next_item: Option<Entry>, next_item: Option<Entry>,

View file

@ -6,7 +6,7 @@ use serde::de::{Error, Visitor};
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt::Formatter; use std::fmt::Formatter;
use std::ops::Deref; use std::ops::{Deref, DerefMut};
#[derive(Clone, PartialEq, Eq, Debug, Serialize)] #[derive(Clone, PartialEq, Eq, Debug, Serialize)]
#[serde(transparent)] #[serde(transparent)]
@ -55,6 +55,12 @@ impl Deref for Value {
} }
} }
impl DerefMut for Value {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl Value { impl Value {
/// Try to convert the entry to the given type. /// Try to convert the entry to the given type.
pub fn to<T: ParseItem>(self) -> Result<T, ParseStringError> { pub fn to<T: ParseItem>(self) -> Result<T, ParseStringError> {