Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Jul 25, 2023
1 parent de41b48 commit 8858dff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{IterError, Metadata, SerDe};
use super::{IterError, Metadata, Miniconf, SerDe};
use core::{fmt::Write, marker::PhantomData};

/// An iterator over the paths in a Miniconf namespace.
Expand Down Expand Up @@ -32,7 +32,7 @@ impl<M, S, const L: usize, P, Y> Default for MiniconfIter<M, S, L, P, Y> {
}
}

impl<M: Miniconf<Y> + SerDe<S>, S, const L: usize, P, Y> MiniconfIter<M, S, L, P, Y> {
impl<M: Miniconf<Y> + SerDe<S, Y>, S, const L: usize, P, Y> MiniconfIter<M, S, L, P, Y> {
pub fn metadata() -> Result<Metadata, IterError> {
let meta = M::metadata(M::SEPARATOR.len_utf8());
if L < meta.max_depth {
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ pub struct Metadata {
pub count: usize,
}

pub trait Style {}
pub struct Outer;
impl Style for Outer {}
pub struct Inner;
impl Style for Inner {}

/// Trait exposing serialization/deserialization of elements by path.
pub trait Miniconf<Y: Style> {
pub trait Miniconf<Y> {
/// Deserialize an element by path.
///
/// # Args
Expand Down
24 changes: 4 additions & 20 deletions src/option.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{Error, Inner, IterError, Metadata, Miniconf, Outer};
use core::{
fmt::Write,
ops::{Deref, DerefMut},
};
use core::fmt::Write;

/// An `Option` that exposes its value through their [`Miniconf`] implementation.
///
Expand Down Expand Up @@ -32,20 +29,7 @@ use core::{
///
/// An `miniconf::Option` can be constructed using [`From<core::option::Option>`]/[`Into<miniconf::Option>`]
/// and the contained value can be accessed through [`Deref`]/[`DerefMut`].
#[derive(
Clone,
Copy,
Default,
PartialEq,
Eq,
Debug,
PartialOrd,
Ord,
Hash,
serde::Serialize,
serde::Deserialize,
)]
#[repr(transparent)]

pub type Option<T> = core::option::Option<T>;

impl<T: Miniconf<Outer>> Miniconf<Inner> for Option<T> {
Expand All @@ -58,7 +42,7 @@ impl<T: Miniconf<Outer>> Miniconf<Inner> for Option<T> {
P: Iterator<Item = &'a str>,
D: serde::Deserializer<'b>,
{
if let Some(inner) = self.0.as_mut() {
if let Some(inner) = self.as_mut() {
inner.set_path(path_parts, de)
} else {
Err(Error::PathAbsent)
Expand All @@ -70,7 +54,7 @@ impl<T: Miniconf<Outer>> Miniconf<Inner> for Option<T> {
P: Iterator<Item = &'a str>,
S: serde::Serializer,
{
if let Some(inner) = self.0.as_ref() {
if let Some(inner) = self.as_ref() {
inner.get_path(path_parts, ser)
} else {
Err(Error::PathAbsent)
Expand Down
2 changes: 1 addition & 1 deletion tests/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn option_get_set_some() {
assert_eq!(&data[..len], b"5");

settings.set("/value/data", b"7").unwrap();
assert_eq!((*settings.value).as_ref().unwrap().data, 7);
assert_eq!(settings.value.as_ref().unwrap().data, 7);
}

#[test]
Expand Down

0 comments on commit 8858dff

Please sign in to comment.