nstree 1.0.0

construct branched 'namespace strings' for nested subcomponents, often for logging
Documentation
//! Contains recursive reference-ish implementations of [`NamespacePath`] and [`RawNamespacePath`]
use super::{NamespacePath, RawNamespacePath};
use crate::NamespaceComponent;
use core::fmt;

impl<T: ?Sized + NamespacePath> NamespacePath for &'_ T {
    #[inline]
    fn components(&self) -> impl IntoIterator<Item = NamespaceComponent<'_>> {
        T::components(self)
    }

    #[inline]
    fn components_hint(&self) -> super::NamespaceComponentsHint {
        T::components_hint(self)
    }
}

impl<T: ?Sized + NamespacePath> NamespacePath for &'_ mut T {
    #[inline]
    fn components(&self) -> impl IntoIterator<Item = NamespaceComponent<'_>> {
        T::components(self)
    }

    #[inline]
    fn components_hint(&self) -> super::NamespaceComponentsHint {
        T::components_hint(self)
    }
}

#[cfg(any(feature = "alloc", test))]
impl<T: ?Sized + NamespacePath> NamespacePath for alloc::boxed::Box<T> {
    #[inline]
    fn components(&self) -> impl IntoIterator<Item = NamespaceComponent<'_>> {
        T::components(self)
    }

    #[inline]
    fn components_hint(&self) -> super::NamespaceComponentsHint {
        T::components_hint(self)
    }
}

#[cfg(any(feature = "alloc", test))]
impl<T: ?Sized + NamespacePath> NamespacePath for alloc::rc::Rc<T> {
    #[inline]
    fn components(&self) -> impl IntoIterator<Item = NamespaceComponent<'_>> {
        T::components(self)
    }

    #[inline]
    fn components_hint(&self) -> super::NamespaceComponentsHint {
        T::components_hint(self)
    }
}

#[cfg(any(feature = "alloc", test))]
impl<T: ?Sized + NamespacePath> NamespacePath for alloc::sync::Arc<T> {
    #[inline]
    fn components(&self) -> impl IntoIterator<Item = NamespaceComponent<'_>> {
        T::components(self)
    }

    #[inline]
    fn components_hint(&self) -> super::NamespaceComponentsHint {
        T::components_hint(self)
    }
}

impl<T: ?Sized + RawNamespacePath> RawNamespacePath for &'_ T {
    #[inline]
    fn raw_components(&self) -> impl IntoIterator<Item = impl fmt::Display> {
        T::raw_components(self)
    }
}

impl<T: ?Sized + RawNamespacePath> RawNamespacePath for &'_ mut T {
    #[inline]
    fn raw_components(&self) -> impl IntoIterator<Item = impl fmt::Display> {
        T::raw_components(self)
    }
}

#[cfg(any(feature = "alloc", test))]
impl<T: ?Sized + RawNamespacePath> RawNamespacePath for alloc::boxed::Box<T> {
    #[inline]
    fn raw_components(&self) -> impl IntoIterator<Item = impl fmt::Display> {
        T::raw_components(self)
    }
}

#[cfg(any(feature = "alloc", test))]
impl<T: ?Sized + RawNamespacePath> RawNamespacePath for alloc::rc::Rc<T> {
    #[inline]
    fn raw_components(&self) -> impl IntoIterator<Item = impl fmt::Display> {
        T::raw_components(self)
    }
}

#[cfg(any(feature = "alloc", test))]
impl<T: ?Sized + RawNamespacePath> RawNamespacePath for alloc::sync::Arc<T> {
    #[inline]
    fn raw_components(&self) -> impl IntoIterator<Item = impl fmt::Display> {
        T::raw_components(self)
    }
}

// nstree - nested namespace string-generating abstraction library
// Copyright (C) 2025  Matti <infomorphic-matti at protonmail dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
// ------
// SPDX-License-Identifier: GPL-3.0-or-later