Skip to content

Commit

Permalink
fix: refined
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Sep 14, 2024
1 parent e87f9a4 commit c2f3619
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
12 changes: 2 additions & 10 deletions src/refined.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::{Display, Formatter};
use std::marker::PhantomData;

use crate::result::Error;
use crate::rule::Rule;
Expand All @@ -23,7 +22,6 @@ where
RULE: Rule,
{
value: RULE::Item,
_rule: PhantomData<RULE>,
}

impl<RULE, T> Serialize for Refined<RULE>
Expand Down Expand Up @@ -61,18 +59,12 @@ where
{
pub fn new(value: T) -> Result<Self, Error> {
RULE::validate(&value).map_err(|e| Error::new(e.to_string()))?;
Ok(Self {
value,
_rule: Default::default(),
})
Ok(Self { value })
}

pub fn unsafe_new(value: T) -> Self {
RULE::validate(&value).expect("initialization by `unsafe_new` failed");
Self {
value,
_rule: Default::default(),
}
Self { value }
}

pub fn value(&self) -> &RULE::Item {
Expand Down
5 changes: 3 additions & 2 deletions src/rule/non_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ impl<I: ExactSizeIterator + EmptyDefinition> NonEmpty<I> {
F: FnMut(I::Item) -> B,
{
let map_into_iter = self.into_value().map(f);
Refined::new(map_into_iter).expect("This error is always unreachable")
Refined::<NonEmptyRule<Map<I, F>>>::new(map_into_iter)
.expect("This error is always unreachable")
}

pub fn collect<B: FromIterator<I::Item> + EmptyDefinition>(self) -> NonEmpty<B>
where
Self: Sized,
{
Refined::new(FromIterator::from_iter(self.into_value()))
NonEmpty::<B>::new(FromIterator::from_iter(self.into_value()))
.expect("This error is always unreachable")
}
}

0 comments on commit c2f3619

Please sign in to comment.