Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: unsealed PathComponentKind to allow custom key types in garde.
  • Loading branch information
Wicpar committed Dec 4, 2023
commit de1dfe87f0409a5ab626a54f719b958ecae3ba9d
8 changes: 1 addition & 7 deletions garde/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,12 @@ impl std::fmt::Display for NoKey {
}
}

pub trait PathComponentKind: std::fmt::Display + ToCompactString + private::Sealed {
pub trait PathComponentKind: std::fmt::Display + ToCompactString {
fn component_kind() -> Kind;
}

macro_rules! impl_path_component_kind {
($(@$($G:lifetime)*;)? $T:ty => $which:ident) => {
impl $(<$($G),*>)? private::Sealed for $T {}
impl $(<$($G),*>)? PathComponentKind for $T {
fn component_kind() -> Kind {
Kind::$which
Expand All @@ -132,17 +131,12 @@ impl_path_component_kind!(String => Key);
impl_path_component_kind!(CompactString => Key);
impl_path_component_kind!(NoKey => None);

impl<'a, T: PathComponentKind> private::Sealed for &'a T {}
impl<'a, T: PathComponentKind> PathComponentKind for &'a T {
fn component_kind() -> Kind {
T::component_kind()
}
}

mod private {
pub trait Sealed {}
}

impl Path {
pub fn empty() -> Self {
Self {
Expand Down