qubit-validator 0.1.2

Type-safe validation traits and registries for Qubit applications
Documentation
// =============================================================================
//    Copyright (c) 2025 - 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================

//! Linked registration source locations.

/// Source location for one linked registration.
///
/// # Examples
///
/// ```
/// use qubit_validator::RegistrationSource;
///
/// let source = RegistrationSource::new("rules", "rules::text", "src/text.rs", 12);
/// assert_eq!(source.crate_name(), "rules");
/// assert_eq!(source.line(), 12);
/// ```
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct RegistrationSource {
    /// Cargo package which declared the registration.
    crate_name: &'static str,
    /// Rust module path which declared the registration.
    module_path: &'static str,
    /// Source file recorded at compile time.
    file: &'static str,
    /// One-based source line recorded at compile time.
    line: u32,
}

impl RegistrationSource {
    /// Creates the source location of a validator registration.
    ///
    /// `crate_name`, `module_path`, and `file` identify the declaring crate,
    /// module, and source file, while `line` is the one-based source line.
    /// All text fields must live for the duration of the program. This
    /// constructor only stores the supplied metadata and does not access the
    /// file system. It can be used for local registrations as well as the
    /// registrations generated by `register_validator!`.
    ///
    /// # Parameters
    ///
    /// * `crate_name` - Cargo package which declared the registration.
    /// * `module_path` - Rust module path which declared the registration.
    /// * `file` - Source file recorded at compile time.
    /// * `line` - One-based source line recorded at compile time.
    ///
    /// # Returns
    ///
    /// Returns the source location containing the supplied metadata.
    #[must_use]
    #[inline]
    pub const fn new(crate_name: &'static str, module_path: &'static str, file: &'static str, line: u32) -> Self {
        Self {
            crate_name,
            module_path,
            file,
            line,
        }
    }

    /// Returns the declaring crate name.
    ///
    /// # Returns
    ///
    /// Returns the Cargo package name stored in this source location.
    #[must_use]
    #[inline]
    pub const fn crate_name(&self) -> &'static str {
        self.crate_name
    }

    /// Returns the declaring module path.
    ///
    /// # Returns
    ///
    /// Returns the Rust module path stored in this source location.
    #[must_use]
    #[inline]
    pub const fn module_path(&self) -> &'static str {
        self.module_path
    }

    /// Returns the source file path.
    ///
    /// # Returns
    ///
    /// Returns the compile-time source file path stored in this location.
    #[must_use]
    #[inline]
    pub const fn file(&self) -> &'static str {
        self.file
    }

    /// Returns the one-based source line.
    ///
    /// # Returns
    ///
    /// Returns the compile-time line number stored in this location.
    #[must_use]
    #[inline]
    pub const fn line(&self) -> u32 {
        self.line
    }
}