1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

macro_rules! impl_to_path_to_set {
    (
        impl[ $($impl_params:tt)* ] $self:ty
        $(where[ $($where_clause:tt)* ])?
    ) => (
        impl< $($impl_params)* > $self
        where
            $($($where_clause)*)?
        {
            /// Constructs a NestedFieldPath from this.
            #[inline(always)]
            pub const fn into_path(self) -> NestedFieldPath<(Self,)> {
                NestedFieldPath::one(self)
            }

            /// Constructs a FieldPathSet from this.
            #[inline(always)]
            pub const fn into_set(self) -> FieldPathSet<(Self,), UniquePaths> {
                FieldPathSet::one(self)
            }
        }

        // Defined for the `fp` macro
        impl< $($impl_params)* > $self
        where
            Self: ConstDefault,
            $($($where_clause)*)?
        {
            #[doc(hidden)]
            pub const NEW_ALIASED:Self=Self::DEFAULT;

            #[doc(hidden)]
            pub const unsafe fn set_uniqueness(self)->Self{
                self
            }
        }
    )
}

////////////////////////////////////////////////////////////////////////////////

/// A marker trait for type-level strings.
///
/// This is only implemented on [`TStr`](../struct.TStr.html).
///
pub trait IsTStr: Sealed + Debug + Copy + ConstDefault {}

/// A marker trait to assert that `P` is a [`TStr`](crate::TStr).
#[doc(hidden)]
pub trait AssertTStrParam<P>: AssertTStrParamSealed<P> {}

mod is_tstr_param_sealed {
    pub trait AssertTStrParamSealed<P> {}
}
use is_tstr_param_sealed::AssertTStrParamSealed;

impl<This: ?Sized, P> AssertTStrParamSealed<TStr<P>> for This {}
impl<This: ?Sized, P> AssertTStrParam<TStr<P>> for This {}

impl<T> IsTStr for TStr<T> {}

impl<T> Debug for TStr<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("TStr").finish()
    }
}

impl<T> TStr<T> {
    /// Constructs the TStr.
    pub const NEW: Self = TStr(PhantomData);
}

impl_to_path_to_set! {
    impl[T] TStr<T>
}

impl<T> IsSingleFieldPath for TStr<T> {}

impl<T> IsMultiFieldPath for TStr<T> {
    type PathUniqueness=UniquePaths;
}

impl<T> Copy for TStr<T> {}
impl<T> Clone for TStr<T> {
    #[inline(always)]
    fn clone(&self) -> Self {
        *self
    }
}
impl<T> ConstDefault for TStr<T> {
    const DEFAULT: Self = TStr(PhantomData);
}

impl<T> ToTString for TStr<T> {
    type Output = Self;
}

impl_cmp_traits! {
    impl[T] TStr<T>
    where[]
}

////////////////////////////////////////////////////////////////////////////////

impl<V, F> VariantField<V, F>
where
    V: ConstDefault,
    F: ConstDefault,
{
    /// Constructs a `VariantField<V,F>`
    pub const NEW: Self = ConstDefault::DEFAULT;
}

impl_to_path_to_set! {
    impl[V,F] VariantField<V,F>
}

impl<V, F> VariantField<V, F> {
    /// Constructs a VariantField from the name of the variant,and field.
    ///
    /// Both `name` and `field` is expected to be a [::structural::path::TStr].
    pub const fn new(variant: V, field: F) -> Self {
        Self { variant, field }
    }
}

impl<V, F> IsSingleFieldPath for VariantField<V, F> {}

impl<V, F> IsMultiFieldPath for VariantField<V, F> {
    type PathUniqueness=UniquePaths;
}

impl<T, U> Debug for VariantField<T, U> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("VariantField").finish()
    }
}

impl<V, F> ConstDefault for VariantField<V, F>
where
    V: ConstDefault,
    F: ConstDefault,
{
    const DEFAULT: Self = Self {
        variant: ConstDefault::DEFAULT,
        field: ConstDefault::DEFAULT,
    };
}

impl_cmp_traits! {
    impl[V,F] VariantField<V,F>
    where[]
}

////////////////////////////////////////////////////////////////////////////////

impl<V> VariantName<V>
where
    V: ConstDefault,
{
    /// Constructs a VariantName.
    pub const NEW: Self = Self::DEFAULT;
}

impl_to_path_to_set! {
    impl[V] VariantName<V>
}

impl<V> VariantName<V> {
    /// Constructs a VariantName from `name`.
    ///
    /// `name` is expected to be a [::structural::path::TStr].
    pub fn new(name: V) -> Self {
        Self { name }
    }
}

impl<V> IsSingleFieldPath for VariantName<V> {}

impl<T> IsMultiFieldPath for VariantName<T> {
    type PathUniqueness=UniquePaths;
}

impl<T> Debug for VariantName<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("VariantName").finish()
    }
}

impl<V> ConstDefault for VariantName<V>
where
    V: ConstDefault,
{
    const DEFAULT: Self = VariantName {
        name: ConstDefault::DEFAULT,
    };
}

impl_cmp_traits! {
    impl[T] VariantName<T>
    where[]
}

////////////////////////////////////////////////////////////////////////////////