#![allow(non_snake_case, non_camel_case_types)]
use crate::type_level::collection_traits::{
Append, AppendOut, PushBack, PushBackOut, ToTList, ToTListOut, ToTString,
};
pub use crate::{field_path_aliases, fp, FP};
use core_extensions::ConstDefault;
use std_::{
fmt::{self, Debug},
marker::PhantomData,
mem::ManuallyDrop,
};
#[cfg(test)]
mod tests;
pub mod array_paths;
mod to_usize;
include! { "./path/path_components.rs" }
pub use crate::{
FieldPathSet, NestedFieldPath, NestedFieldPathSet, TStr, VariantField, VariantName,
};
pub mod aliases {
field_path_aliases! {
index_0=0,
index_1=1,
index_2=2,
index_3=3,
index_4=4,
index_5=5,
index_6=6,
index_7=7,
index_8=8,
}
}
pub mod string_aliases {
tstr_aliases! {
str_0=0,
str_1=1,
str_2=2,
str_3=3,
str_4=4,
str_5=5,
str_6=6,
str_7=7,
str_8=8,
str_9=9,
str_underscore="_",
}
}
mod sealed {
pub trait Sealed {}
}
use self::sealed::Sealed;
impl<T> Sealed for TStr<T> {}
pub trait IsSingleFieldPath: Sized {}
pub unsafe trait ShallowFieldPath: Sized {}
pub trait IsMultiFieldPath: Sized {
type PathUniqueness;
}
impl<T> IsSingleFieldPath for NestedFieldPath<T> {}
unsafe impl<F0> ShallowFieldPath for NestedFieldPath<(F0,)> where F0: ShallowFieldPath {}
impl<T> IsMultiFieldPath for NestedFieldPath<T> {
type PathUniqueness = UniquePaths;
}
impl<T> Debug for NestedFieldPath<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("NestedFieldPath").finish()
}
}
impl<T> NestedFieldPath<T>
where
T: ConstDefault,
{
pub const NEW: Self = Self::DEFAULT;
}
impl<T> NestedFieldPath<T>
where
Self: ConstDefault,
{
#[doc(hidden)]
pub const NEW_ALIASED: Self = Self::DEFAULT;
#[doc(hidden)]
pub const unsafe fn set_uniqueness(self) -> Self {
self
}
}
impl<T> NestedFieldPath<(T,)> {
#[inline(always)]
pub const fn one(value: T) -> Self {
Self { list: (value,) }
}
}
impl<T> NestedFieldPath<T> {
#[inline(always)]
pub const fn many(list: T) -> Self {
Self { list }
}
}
impl<T> ConstDefault for NestedFieldPath<T>
where
T: ConstDefault,
{
const DEFAULT: Self = NestedFieldPath {
list: ConstDefault::DEFAULT,
};
}
impl<S> ToTString for NestedFieldPath<(TStr<S>,)> {
type Output = TStr<S>;
}
impl<T> ToTList for NestedFieldPath<T>
where
T: ToTList,
{
type Output = ToTListOut<T>;
}
impl<T, S> PushBack<S> for NestedFieldPath<T>
where
T: PushBack<S>,
{
type Output = NestedFieldPath<PushBackOut<T, S>>;
}
impl<T, U> Append<NestedFieldPath<U>> for NestedFieldPath<T>
where
T: Append<U>,
{
type Output = NestedFieldPath<AppendOut<T, U>>;
}
impl<T> NestedFieldPath<T> {
#[inline(always)]
pub fn push<U, V>(self, _other: U) -> NestedFieldPath<V>
where
Self: PushBack<U, Output = NestedFieldPath<V>>,
NestedFieldPath<V>: ConstDefault,
{
ConstDefault::DEFAULT
}
#[inline(always)]
pub fn append<U>(self, _other: NestedFieldPath<U>) -> NestedFieldPath<AppendOut<T, U>>
where
T: Append<U>,
NestedFieldPath<AppendOut<T, U>>: ConstDefault,
{
ConstDefault::DEFAULT
}
#[inline(always)]
pub const fn into_set(self) -> FieldPathSet<(Self,), UniquePaths> {
FieldPathSet::one(self)
}
}
impl<C> NestedFieldPath<(C,)> {
pub fn into_component(self) -> C {
self.list.0
}
}
impl_cmp_traits! {
impl[T] NestedFieldPath<T>
where[]
}
#[derive(Debug, Copy, Clone)]
pub struct UniquePaths;
#[derive(Debug, Copy, Clone)]
pub struct AliasedPaths;
impl<T, U> IsSingleFieldPath for FieldPathSet<(T,), U> {}
impl<T, U> IsMultiFieldPath for FieldPathSet<T, U> {
type PathUniqueness = U;
}
impl<T> ConstDefault for FieldPathSet<T, AliasedPaths>
where
T: ConstDefault,
{
const DEFAULT: Self = FieldPathSet {
paths: ManuallyDrop::new(ConstDefault::DEFAULT),
uniqueness: PhantomData,
};
}
impl<T> Default for FieldPathSet<T, AliasedPaths>
where
T: Default,
{
#[inline(always)]
fn default() -> Self {
Self::many(T::default())
}
}
impl<T> FieldPathSet<(T,), UniquePaths> {
pub const fn one(val: T) -> Self {
FieldPathSet {
paths: ManuallyDrop::new((val,)),
uniqueness: PhantomData,
}
}
}
impl<T> FieldPathSet<T, AliasedPaths> {
pub const fn many(paths: T) -> Self {
FieldPathSet {
paths: ManuallyDrop::new(paths),
uniqueness: PhantomData,
}
}
}
impl<T> FieldPathSet<LargePathSet<T>, AliasedPaths> {
pub const fn large(paths: T) -> Self {
FieldPathSet {
paths: ManuallyDrop::new(LargePathSet(paths)),
uniqueness: PhantomData,
}
}
}
impl<T> FieldPathSet<T, AliasedPaths>
where
T: ConstDefault,
{
pub const NEW: Self = Self::DEFAULT;
}
impl<T, U> FieldPathSet<T, U>
where
T: ConstDefault,
{
pub const NEW_ALIASED: FieldPathSet<T, AliasedPaths> = FieldPathSet::NEW;
}
impl<T> FieldPathSet<T, UniquePaths> {
#[inline(always)]
pub const fn downgrade(self) -> FieldPathSet<T, AliasedPaths> {
FieldPathSet {
paths: self.paths,
uniqueness: PhantomData,
}
}
}
impl<T> FieldPathSet<T, AliasedPaths> {
#[inline(always)]
pub const unsafe fn upgrade_unchecked(self) -> FieldPathSet<T, UniquePaths> {
self.set_uniqueness()
}
#[inline(always)]
pub const unsafe fn set_uniqueness<U>(self) -> FieldPathSet<T, U> {
FieldPathSet {
paths: self.paths,
uniqueness: PhantomData,
}
}
}
impl<T, U> FieldPathSet<T, U> {
#[inline(always)]
pub const fn into_paths(self) -> T {
ManuallyDrop::into_inner(self.paths)
}
}
impl<T, U> FieldPathSet<(T,), U> {
#[inline(always)]
pub fn into_path(self) -> T {
ManuallyDrop::into_inner(self.paths).0
}
}
impl<T, U> FieldPathSet<T, U> {
#[inline(always)]
pub fn push<O, Out>(self, _other: O) -> FieldPathSet<Out, AliasedPaths>
where
Self: PushBack<O, Output = FieldPathSet<Out, AliasedPaths>>,
FieldPathSet<Out, AliasedPaths>: ConstDefault,
{
ConstDefault::DEFAULT
}
#[inline(always)]
pub fn append<T2, U2>(
self,
_other: FieldPathSet<T2, U2>,
) -> FieldPathSet<AppendOut<T, T2>, AliasedPaths>
where
T: Append<T2>,
FieldPathSet<AppendOut<T, T2>, AliasedPaths>: ConstDefault,
{
ConstDefault::DEFAULT
}
}
impl<T, U> ToTList for FieldPathSet<T, U>
where
T: ToTList,
{
type Output = ToTListOut<T>;
}
impl<T, U, P> PushBack<NestedFieldPath<P>> for FieldPathSet<T, U>
where
T: PushBack<NestedFieldPath<P>>,
{
type Output = FieldPathSet<PushBackOut<T, NestedFieldPath<P>>, AliasedPaths>;
}
impl<T, U, P, U2> PushBack<FieldPathSet<(P,), U2>> for FieldPathSet<T, U>
where
T: PushBack<P>,
{
type Output = FieldPathSet<PushBackOut<T, P>, AliasedPaths>;
}
impl<T, T2, U, U2> Append<FieldPathSet<T2, U2>> for FieldPathSet<T, U>
where
T: Append<T2>,
{
type Output = FieldPathSet<AppendOut<T, T2>, AliasedPaths>;
}
impl_cmp_traits! {
impl[T,U] FieldPathSet<T,U>
where[]
}
impl<F, S> NestedFieldPathSet<F, S, AliasedPaths>
where
F: ConstDefault,
S: ConstDefault,
{
pub const NEW: Self = Self::DEFAULT;
}
impl<F, S, U> NestedFieldPathSet<F, S, U>
where
F: ConstDefault,
S: ConstDefault,
{
pub const NEW_ALIASED: NestedFieldPathSet<F, S, AliasedPaths> = NestedFieldPathSet::NEW;
}
impl<F, S> Default for NestedFieldPathSet<F, S, AliasedPaths>
where
F: Default,
S: Default,
{
fn default() -> Self {
Self::new(Default::default(), Default::default())
}
}
impl<F, S, U> NestedFieldPathSet<F, S, U> {
pub const fn new(nested: F, set: FieldPathSet<S, U>) -> Self {
Self {
nested: ManuallyDrop::new(nested),
set,
}
}
pub const fn into_inner(self) -> (F, FieldPathSet<S, U>) {
(ManuallyDrop::into_inner(self.nested), self.set)
}
pub const fn into_nested(self) -> F {
ManuallyDrop::into_inner(self.nested)
}
pub const fn into_set(self) -> FieldPathSet<S, U> {
self.set
}
}
impl<F, S> NestedFieldPathSet<F, S, UniquePaths> {
#[inline(always)]
pub const fn downgrade(self) -> NestedFieldPathSet<F, S, AliasedPaths> {
NestedFieldPathSet {
nested: self.nested,
set: self.set.downgrade(),
}
}
}
impl<F, S> NestedFieldPathSet<F, S, AliasedPaths> {
#[inline(always)]
pub const unsafe fn upgrade_unchecked(self) -> NestedFieldPathSet<F, S, UniquePaths> {
self.set_uniqueness()
}
#[inline(always)]
pub const unsafe fn set_uniqueness<U>(self) -> NestedFieldPathSet<F, S, U> {
NestedFieldPathSet {
nested: self.nested,
set: self.set.set_uniqueness(),
}
}
}
impl<F, S, U> IsSingleFieldPath for NestedFieldPathSet<F, (S,), U> {}
impl<F, S, U> IsMultiFieldPath for NestedFieldPathSet<F, S, U> {
type PathUniqueness = U;
}
impl<F, S> ConstDefault for NestedFieldPathSet<F, S, AliasedPaths>
where
F: ConstDefault,
S: ConstDefault,
{
const DEFAULT: Self = NestedFieldPathSet {
nested: ConstDefault::DEFAULT,
set: ConstDefault::DEFAULT,
};
}
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct LargePathSet<T>(pub T);
impl<T> ConstDefault for LargePathSet<T>
where
T: ConstDefault,
{
const DEFAULT: Self = LargePathSet(T::DEFAULT);
}
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[doc(hidden)]
pub struct SmallPathSet<T>(pub(crate) T);
impl<T> ConstDefault for SmallPathSet<T>
where
T: ConstDefault,
{
const DEFAULT: Self = SmallPathSet(T::DEFAULT);
}
pub trait IntoAliasing: IsMultiFieldPath {
type Output: IsMultiFieldPath<PathUniqueness = AliasedPaths>;
}
pub type IntoAliasingOut<This> = <This as IntoAliasing>::Output;
impl<F, U> IntoAliasing for FieldPathSet<F, U> {
type Output = FieldPathSet<F, AliasedPaths>;
}
impl<F, S, U> IntoAliasing for NestedFieldPathSet<F, S, U> {
type Output = NestedFieldPathSet<F, S, AliasedPaths>;
}