1#![doc = include_str!("../README.md")]
2
3pub mod error;
4pub mod rules;
5pub mod validate;
6
7pub use error::{Error, Path, Report};
8#[cfg(feature = "derive")]
9pub use garde_derive::{select, Validate};
10pub use validate::{Unvalidated, Valid, Validate};
11
12pub type Result = ::core::result::Result<(), Error>;
13
14pub mod external {
15 pub use {compact_str, smallvec};
16}
17
18#[doc(hidden)]
19pub mod util {
20 use crate::error::PathComponentKind;
21 use crate::Path;
22
23 #[inline]
24 pub fn __make_nested_path<'a, C: PathComponentKind + Clone + 'a>(
25 mut parent: impl FnMut() -> Path + 'a,
26 component: C,
27 ) -> impl FnMut() -> Path + 'a {
28 let mut nested = None::<Path>;
29
30 #[inline]
31 move || MaybeJoin::maybe_join(&mut nested, &mut parent, || component.clone())
32 }
33
34 #[doc(hidden)]
35 #[macro_export]
36 macro_rules! __nested_path {
37 ($parent:ident, $key:expr) => {
38 $crate::util::__make_nested_path(&mut $parent, &$key)
39 };
40 }
41
42 pub use crate::__nested_path as nested_path;
43
44 pub trait MaybeJoin {
45 fn maybe_join<C, P, CF>(&mut self, parent: P, component: CF) -> Path
46 where
47 C: PathComponentKind,
48 P: FnMut() -> Path,
49 CF: Fn() -> C;
50 }
51
52 impl MaybeJoin for Option<Path> {
53 #[inline]
54 fn maybe_join<C, P, CF>(&mut self, mut parent: P, component: CF) -> Path
55 where
56 C: PathComponentKind,
57 P: FnMut() -> Path,
58 CF: Fn() -> C,
59 {
60 match self {
61 Some(path) => path.clone(),
62 None => {
63 let path = parent().join(component());
64 *self = Some(path.clone());
65 path
66 }
67 }
68 }
69 }
70}