debtmap 0.16.6

Code complexity and technical debt analyzer
Documentation
//! Constants for purity analysis
//!
//! Contains lists of known pure standard library functions and constant patterns
//! used to classify code purity.

/// Known constant path prefixes that don't affect purity
pub const KNOWN_CONSTANT_PREFIXES: &[&str] = &[
    // Numeric constants
    "std :: i8 ::",
    "std :: i16 ::",
    "std :: i32 ::",
    "std :: i64 ::",
    "std :: i128 ::",
    "std :: isize ::",
    "std :: u8 ::",
    "std :: u16 ::",
    "std :: u32 ::",
    "std :: u64 ::",
    "std :: u128 ::",
    "std :: usize ::",
    "std :: f32 ::",
    "std :: f64 ::",
    // Core versions
    "core :: i8 ::",
    "core :: i16 ::",
    "core :: i32 ::",
    "core :: i64 ::",
    "core :: i128 ::",
    "core :: isize ::",
    "core :: u8 ::",
    "core :: u16 ::",
    "core :: u32 ::",
    "core :: u64 ::",
    "core :: u128 ::",
    "core :: usize ::",
    "core :: f32 ::",
    "core :: f64 ::",
    // Common constants
    "std :: mem :: size_of",
    "std :: mem :: align_of",
    "core :: mem :: size_of",
    "core :: mem :: align_of",
    // Float constants
    "std :: f32 :: consts ::",
    "std :: f64 :: consts ::",
    "core :: f32 :: consts ::",
    "core :: f64 :: consts ::",
];

/// Known constant suffixes that don't affect purity
pub const KNOWN_CONSTANT_SUFFIXES: &[&str] = &[
    ":: MAX",
    ":: MIN",
    ":: BITS",
    ":: EPSILON",
    ":: INFINITY",
    ":: NEG_INFINITY",
    ":: NAN",
    ":: RADIX",
    ":: MANTISSA_DIGITS",
    ":: DIGITS",
    ":: MIN_EXP",
    ":: MAX_EXP",
    ":: MIN_10_EXP",
    ":: MAX_10_EXP",
    ":: MIN_POSITIVE",
    // Common math constants
    ":: PI",
    ":: TAU",
    ":: E",
    ":: FRAC_PI_2",
    ":: FRAC_PI_3",
    ":: FRAC_PI_4",
    ":: FRAC_PI_6",
    ":: FRAC_PI_8",
    ":: FRAC_1_PI",
    ":: FRAC_2_PI",
    ":: FRAC_2_SQRT_PI",
    ":: SQRT_2",
    ":: FRAC_1_SQRT_2",
    ":: LN_2",
    ":: LN_10",
    ":: LOG2_E",
    ":: LOG10_E",
    ":: LOG2_10",
    ":: LOG10_2",
];

/// Standard library functions known to be pure (Spec 261)
/// These take inputs and return outputs without side effects
pub const KNOWN_PURE_STD_FUNCTIONS: &[&str] = &[
    // Option methods
    "Option::map",
    "Option::and_then",
    "Option::or_else",
    "Option::unwrap_or",
    "Option::unwrap_or_else",
    "Option::unwrap_or_default",
    "Option::filter",
    "Option::flatten",
    "Option::zip",
    "Option::ok_or",
    "Option::ok_or_else",
    "Option::is_some",
    "Option::is_none",
    "Option::as_ref",
    "Option::as_mut",
    "Option::cloned",
    "Option::copied",
    // Result methods
    "Result::map",
    "Result::map_err",
    "Result::and_then",
    "Result::or_else",
    "Result::unwrap_or",
    "Result::unwrap_or_else",
    "Result::unwrap_or_default",
    "Result::is_ok",
    "Result::is_err",
    "Result::ok",
    "Result::err",
    "Result::as_ref",
    // Iterator methods (pure when closure is pure)
    "Iterator::map",
    "Iterator::filter",
    "Iterator::filter_map",
    "Iterator::flat_map",
    "Iterator::fold",
    "Iterator::reduce",
    "Iterator::take",
    "Iterator::skip",
    "Iterator::take_while",
    "Iterator::skip_while",
    "Iterator::enumerate",
    "Iterator::zip",
    "Iterator::chain",
    "Iterator::collect",
    "Iterator::count",
    "Iterator::sum",
    "Iterator::product",
    "Iterator::any",
    "Iterator::all",
    "Iterator::find",
    "Iterator::position",
    "Iterator::max",
    "Iterator::min",
    "Iterator::max_by",
    "Iterator::min_by",
    "Iterator::max_by_key",
    "Iterator::min_by_key",
    "Iterator::rev",
    "Iterator::cloned",
    "Iterator::copied",
    "Iterator::peekable",
    "Iterator::fuse",
    "Iterator::flatten",
    // Slice methods
    "slice::iter",
    "slice::len",
    "slice::is_empty",
    "slice::first",
    "slice::last",
    "slice::get",
    "slice::split_at",
    "slice::chunks",
    "slice::windows",
    "slice::contains",
    "slice::starts_with",
    "slice::ends_with",
    "slice::binary_search",
    // String methods
    "str::len",
    "str::is_empty",
    "str::chars",
    "str::bytes",
    "str::contains",
    "str::starts_with",
    "str::ends_with",
    "str::find",
    "str::rfind",
    "str::split",
    "str::trim",
    "str::trim_start",
    "str::trim_end",
    "str::to_lowercase",
    "str::to_uppercase",
    "str::to_string",
    "str::parse",
    // Vec methods (read-only)
    "Vec::len",
    "Vec::is_empty",
    "Vec::capacity",
    "Vec::iter",
    "Vec::first",
    "Vec::last",
    "Vec::get",
    "Vec::contains",
    // HashMap methods (read-only)
    "HashMap::len",
    "HashMap::is_empty",
    "HashMap::get",
    "HashMap::contains_key",
    "HashMap::keys",
    "HashMap::values",
    "HashMap::iter",
    // Clone trait
    "Clone::clone",
    // Default trait
    "Default::default",
    // From/Into traits
    "From::from",
    "Into::into",
    // Comparison traits
    "PartialEq::eq",
    "PartialEq::ne",
    "PartialOrd::partial_cmp",
    "Ord::cmp",
    // Conversion functions
    "std::convert::identity",
    "std::mem::size_of",
    "std::mem::align_of",
    "std::mem::replace",
    "std::mem::take",
    "std::mem::swap",
];

/// Pure method names (without receiver type)
pub const PURE_METHOD_NAMES: &[&str] = &[
    // Option/Result methods
    "map",
    "and_then",
    "or_else",
    "unwrap_or",
    "unwrap_or_else",
    "unwrap_or_default",
    "filter",
    "flatten",
    "zip",
    "ok_or",
    "ok_or_else",
    "is_some",
    "is_none",
    "is_ok",
    "is_err",
    "ok",
    "err",
    "as_ref",
    "cloned",
    "copied",
    // Iterator methods
    "fold",
    "reduce",
    "take",
    "skip",
    "take_while",
    "skip_while",
    "enumerate",
    "chain",
    "collect",
    "count",
    "sum",
    "product",
    "any",
    "all",
    "find",
    "position",
    "max",
    "min",
    "max_by",
    "min_by",
    "max_by_key",
    "min_by_key",
    "rev",
    "peekable",
    "fuse",
    // Slice/Vec/String read methods
    "len",
    "is_empty",
    "first",
    "last",
    "get",
    "iter",
    "contains",
    "starts_with",
    "ends_with",
    "binary_search",
    "chars",
    "bytes",
    "trim",
    "trim_start",
    "trim_end",
    "to_lowercase",
    "to_uppercase",
    "to_string",
    "parse",
    "split",
    "split_at",
    "chunks",
    "windows",
    "capacity",
    "keys",
    "values",
    // Clone/Default/Conversion
    "clone",
    "default",
    "from",
    "into",
    // Comparison
    "eq",
    "ne",
    "partial_cmp",
    "cmp",
];

/// I/O patterns that indicate impure code
pub const IO_PATTERNS: &[&str] = &[
    "print",
    "write",
    "read",
    "File",
    "stdin",
    "stdout",
    "stderr",
    "fs::",
    "io::",
    "net::",
    "TcpStream",
    "UdpSocket",
    "reqwest",
    "tokio",
];

/// Mutation method names
pub const MUTATION_METHODS: &[&str] = &[
    "push",
    "pop",
    "insert",
    "remove",
    "clear",
    "append",
    "extend",
    "retain",
    "truncate",
    "swap",
    "reverse",
    "sort",
    "sort_by",
    "dedup",
    "drain",
    "split_off",
];

/// Iterator methods that take closures
pub const ITERATOR_METHODS: &[&str] = &[
    // Consuming methods
    "map",
    "filter",
    "filter_map",
    "flat_map",
    "flatten",
    "fold",
    "reduce",
    "for_each",
    "try_fold",
    "try_for_each",
    "scan",
    "partition",
    "find",
    "find_map",
    "position",
    "any",
    "all",
    "collect",
    "inspect",
    // Result/Option adapters
    "and_then",
    "or_else",
    "map_or",
    "map_or_else",
];