Skip to content

Commit

Permalink
cleanup std impls
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Nov 12, 2024
1 parent cdd0859 commit 20aca16
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
7 changes: 6 additions & 1 deletion miniconf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ required-features = ["json-core", "derive"]

[[test]]
name = "basic"
required-features = ["derive"]
required-features = ["json-core", "derive"]

[[test]]
name = "generics"
Expand Down Expand Up @@ -89,9 +89,14 @@ required-features = ["json-core", "derive"]
name = "flatten"
required-features = ["json-core", "derive"]

[[test]]
name = "compiletest"
required-features = ["derive"]

[[example]]
name = "common"
crate-type = ["lib"]
required-features = ["derive"]

[[example]]
name = "cli"
Expand Down
48 changes: 15 additions & 33 deletions miniconf/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,24 +758,6 @@ impl<T: TreeAny> TreeAny for Cell<T> {
}
}

impl<T: TreeAny> TreeAny for &Cell<T> {
#[inline]
fn ref_any_by_key<K>(&self, _keys: K) -> Result<&dyn Any, Traversal>
where
K: Keys,
{
Err(Traversal::Access(0, "Can't leak out of Cell"))
}

#[inline]
fn mut_any_by_key<K>(&mut self, _keys: K) -> Result<&mut dyn Any, Traversal>
where
K: Keys,
{
Err(Traversal::Access(0, "Can't leak out of Cell"))
}
}

/////////////////////////////////////////////////////////////////////////////////////////

impl<T: TreeKey> TreeKey for RefCell<T> {
Expand Down Expand Up @@ -807,27 +789,27 @@ impl<T: TreeSerialize> TreeSerialize for RefCell<T> {
}
}

impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &RefCell<T> {
impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for RefCell<T> {
#[inline]
fn deserialize_by_key<K, D>(&mut self, keys: K, de: D) -> Result<usize, Error<D::Error>>
where
K: Keys,
D: Deserializer<'de>,
{
self.try_borrow_mut()
.or(Err(Traversal::Access(0, "Borrowed")))?
.deserialize_by_key(keys, de)
self.get_mut().deserialize_by_key(keys, de)
}
}

impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for RefCell<T> {
impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &RefCell<T> {
#[inline]
fn deserialize_by_key<K, D>(&mut self, keys: K, de: D) -> Result<usize, Error<D::Error>>
where
K: Keys,
D: Deserializer<'de>,
{
self.get_mut().deserialize_by_key(keys, de)
self.try_borrow_mut()
.or(Err(Traversal::Access(0, "Borrowed")))?
.deserialize_by_key(keys, de)
}
}

Expand Down Expand Up @@ -1077,7 +1059,7 @@ mod _alloc {
S: Serializer,
{
self.upgrade()
.ok_or(Traversal::Access(0, "Dropped"))?
.ok_or(Traversal::Absent(0))?
.serialize_by_key(keys, ser)
}
}
Expand All @@ -1090,7 +1072,7 @@ mod _alloc {
D: Deserializer<'de>,
{
self.upgrade()
.ok_or(Traversal::Access(0, "Dropped"))?
.ok_or(Traversal::Absent(0))?
.deserialize_by_key(keys, de)
}
}
Expand Down Expand Up @@ -1201,7 +1183,7 @@ mod _alloc {
S: Serializer,
{
self.upgrade()
.ok_or(Traversal::Access(0, "Dropped"))?
.ok_or(Traversal::Absent(0))?
.serialize_by_key(keys, ser)
}
}
Expand All @@ -1214,7 +1196,7 @@ mod _alloc {
D: Deserializer<'de>,
{
self.upgrade()
.ok_or(Traversal::Access(0, "Dropped"))?
.ok_or(Traversal::Absent(0))?
.deserialize_by_key(keys, de)
}
}
Expand Down Expand Up @@ -1274,28 +1256,28 @@ mod _std {
}
}

impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &Mutex<T> {
impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for Mutex<T> {
#[inline]
fn deserialize_by_key<K, D>(&mut self, keys: K, de: D) -> Result<usize, Error<D::Error>>
where
K: Keys,
D: Deserializer<'de>,
{
(*self)
.lock()
self.get_mut()
.or(Err(Traversal::Access(0, "Poisoned")))?
.deserialize_by_key(keys, de)
}
}

impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for Mutex<T> {
impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &Mutex<T> {
#[inline]
fn deserialize_by_key<K, D>(&mut self, keys: K, de: D) -> Result<usize, Error<D::Error>>
where
K: Keys,
D: Deserializer<'de>,
{
self.get_mut()
(*self)
.lock()
.or(Err(Traversal::Access(0, "Poisoned")))?
.deserialize_by_key(keys, de)
}
Expand Down
2 changes: 1 addition & 1 deletion miniconf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![doc = include_str!("../README.md")]
#![cfg_attr(all(feature = "derive", feature = "json-core"), doc = include_str!("../README.md"))]
#![deny(rust_2018_compatibility)]
#![deny(rust_2018_idioms)]
#![warn(missing_docs)]
Expand Down
9 changes: 9 additions & 0 deletions miniconf/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@ fn tuple() {
}
assert_eq!(s, (9.into(), (9.into(), 9.into()), [9.into(); 3]));
}

#[test]
fn cell() {
use core::cell::RefCell;

let c: RefCell<Leaf<i32>> = Default::default();
let mut r = &c;
common::set_get(&mut r, "", b"9");
}

0 comments on commit 20aca16

Please sign in to comment.