vsec 0.0.1

Detect secrets and in Rust codebases
Documentation
// src/models/constant.rs

use std::path::PathBuf;

use crate::models::Visibility;

/// A constant definition found in source code
#[derive(Debug, Clone)]
pub struct Constant {
    /// The name of the constant
    pub name: String,

    /// The string value of the constant
    pub value: String,

    /// File where this was defined
    pub file: PathBuf,

    /// Line number of definition
    pub line: u32,

    /// Column number
    pub column: u32,

    /// Type annotation if present
    pub type_annotation: Option<String>,

    /// Visibility (pub, pub(crate), etc.)
    pub visibility: Visibility,

    /// Whether this is a static (vs const)
    pub is_static: bool,

    /// Whether this is mutable (for statics)
    pub is_mut: bool,
}

impl Constant {
    pub fn new(name: String, value: String, file: PathBuf, line: u32) -> Self {
        Self {
            name,
            value,
            file,
            line,
            column: 0,
            type_annotation: None,
            visibility: Visibility::Private,
            is_static: false,
            is_mut: false,
        }
    }

    pub fn with_visibility(mut self, visibility: Visibility) -> Self {
        self.visibility = visibility;
        self
    }

    pub fn as_static(mut self) -> Self {
        self.is_static = true;
        self
    }

    pub fn as_mut(mut self) -> Self {
        self.is_mut = true;
        self
    }

    /// Check if this constant is publicly visible
    pub fn is_public(&self) -> bool {
        matches!(self.visibility, Visibility::Public | Visibility::PubCrate)
    }
}