1use core::{fmt, marker::PhantomData};
4
5use refining_core::predicate::{Predicate, PredicateExpected};
6
7pub struct CharsAll<P: Predicate<char> + ?Sized> {
11 predicate: PhantomData<P>,
12}
13
14impl<T: AsRef<str> + ?Sized, P: Predicate<char> + ?Sized> Predicate<T> for CharsAll<P> {
15 fn check(value: &T) -> bool {
16 value.as_ref().chars().all(P::check_value)
17 }
18
19 fn expect(formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
20 write!(
21 formatter,
22 "string with all ({expected})",
23 expected = P::expected()
24 )
25 }
26
27 fn expect_code(formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
28 write!(
29 formatter,
30 "str::chars::all<{expected:?}>",
31 expected = P::expected()
32 )
33 }
34}
35
36pub struct CharsAny<P: Predicate<char> + ?Sized> {
40 predicate: PhantomData<P>,
41}
42
43impl<T: AsRef<str> + ?Sized, P: Predicate<char> + ?Sized> Predicate<T> for CharsAny<P> {
44 fn check(value: &T) -> bool {
45 value.as_ref().chars().any(P::check_value)
46 }
47
48 fn expect(formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
49 write!(
50 formatter,
51 "string with any ({expected})",
52 expected = P::expected()
53 )
54 }
55
56 fn expect_code(formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
57 write!(
58 formatter,
59 "str::chars::any<{expected:?}>",
60 expected = P::expected()
61 )
62 }
63}