nstree 1.0.0

construct branched 'namespace strings' for nested subcomponents, often for logging
Documentation
//! Utility module for something that easily translates between [`IntoNamespacePath`] and
//! [`IntoRawNamespacePath`].

use super::{IntoNamespacePath, IntoRawNamespacePath, RawNamespacePathWrapper};

/// Utility structure that takes an [`IntoNamespacePath`], and provides an implementation of
/// [`IntoRawNamespacePath`] that produces a [`RawNamespacePath`][rnsp] based upon the
/// [`NamespacePath`][nsp] that the inner structure itself produces.
///
/// This is commonly returned from the [`IntoNamespacePath::into_into_raw`] provided method.
///
/// [nsp]: `crate::NamespacePath`
/// [rnsp]: `crate::RawNamespacePath`
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub struct IntoIntoRawNSPath<T>(pub T);

impl<T> From<T> for IntoIntoRawNSPath<T> {
    #[inline]
    fn from(value: T) -> Self {
        Self(value)
    }
}

impl<T: IntoNamespacePath> IntoNamespacePath for IntoIntoRawNSPath<T> {
    type NSPath = T::NSPath;

    #[inline]
    fn into_namespace_path(self) -> Self::NSPath {
        self.0.into_namespace_path()
    }

    // In this case, we don't want to keep wrapping things.
    #[inline]
    fn into_into_raw(self) -> impl IntoRawNamespacePath
    where
        Self: Sized,
    {
        self
    }
}

impl<T: IntoNamespacePath> IntoRawNamespacePath for IntoIntoRawNSPath<T> {
    type RawNSPath = RawNamespacePathWrapper<T::NSPath>;

    #[inline]
    fn into_raw_namespace_path(self) -> Self::RawNSPath {
        self.0.into_namespace_path().into()
    }
}

// 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