diff --git a/miniconf/Cargo.toml b/miniconf/Cargo.toml index c6a9edb5..d66e081c 100644 --- a/miniconf/Cargo.toml +++ b/miniconf/Cargo.toml @@ -51,7 +51,7 @@ required-features = ["json-core", "derive"] [[test]] name = "basic" -required-features = ["derive"] +required-features = ["json-core", "derive"] [[test]] name = "generics" @@ -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" diff --git a/miniconf/src/impls.rs b/miniconf/src/impls.rs index b2d66ad3..b266810c 100644 --- a/miniconf/src/impls.rs +++ b/miniconf/src/impls.rs @@ -758,24 +758,6 @@ impl TreeAny for Cell { } } -impl TreeAny for &Cell { - #[inline] - fn ref_any_by_key(&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(&mut self, _keys: K) -> Result<&mut dyn Any, Traversal> - where - K: Keys, - { - Err(Traversal::Access(0, "Can't leak out of Cell")) - } -} - ///////////////////////////////////////////////////////////////////////////////////////// impl TreeKey for RefCell { @@ -807,27 +789,27 @@ impl TreeSerialize for RefCell { } } -impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &RefCell { +impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for RefCell { #[inline] fn deserialize_by_key(&mut self, keys: K, de: D) -> Result> 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 { +impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &RefCell { #[inline] fn deserialize_by_key(&mut self, keys: K, de: D) -> Result> 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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -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) } } @@ -1274,28 +1256,28 @@ mod _std { } } - impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &Mutex { + impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for Mutex { #[inline] fn deserialize_by_key(&mut self, keys: K, de: D) -> Result> 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 { + impl<'de, T: TreeDeserialize<'de>> TreeDeserialize<'de> for &Mutex { #[inline] fn deserialize_by_key(&mut self, keys: K, de: D) -> Result> where K: Keys, D: Deserializer<'de>, { - self.get_mut() + (*self) + .lock() .or(Err(Traversal::Access(0, "Poisoned")))? .deserialize_by_key(keys, de) } diff --git a/miniconf/src/lib.rs b/miniconf/src/lib.rs index 209ca7a7..b7a5b26c 100644 --- a/miniconf/src/lib.rs +++ b/miniconf/src/lib.rs @@ -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)] diff --git a/miniconf/tests/basic.rs b/miniconf/tests/basic.rs index 57439b2d..c31a0a06 100644 --- a/miniconf/tests/basic.rs +++ b/miniconf/tests/basic.rs @@ -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> = Default::default(); + let mut r = &c; + common::set_get(&mut r, "", b"9"); +}