refined_type/rule/
non_empty.rs1mod non_empty_map;
2mod non_empty_set;
3mod non_empty_string;
4mod non_empty_vec;
5mod non_empty_vec_deque;
6
7use crate::rule::composer::Not;
8use crate::rule::{EmptyDefinition, EmptyRule};
9use crate::Refined;
10pub use non_empty_map::*;
11pub use non_empty_set::*;
12pub use non_empty_string::*;
13pub use non_empty_vec::*;
14pub use non_empty_vec_deque::*;
15use std::fmt::Debug;
16use std::iter::Map;
17
18pub type NonEmpty<T> = Refined<NonEmptyRule<T>>;
21
22pub type NonEmptyRule<T> = Not<EmptyRule<T>>;
35
36impl<I: Debug + ExactSizeIterator + EmptyDefinition> NonEmpty<I> {
37 pub fn map<B, F>(self, f: F) -> Refined<NonEmptyRule<Map<I, F>>>
38 where
39 Self: Sized,
40 F: FnMut(I::Item) -> B,
41 {
42 let map_into_iter = self.into_value().map(f);
43 Refined::<NonEmptyRule<Map<I, F>>>::new(map_into_iter)
44 .expect("This error is always unreachable")
45 }
46
47 pub fn collect<B: Debug + FromIterator<I::Item> + EmptyDefinition>(self) -> NonEmpty<B>
48 where
49 Self: Sized,
50 {
51 NonEmpty::<B>::new(FromIterator::from_iter(self.into_value()))
52 .expect("This error is always unreachable")
53 }
54}