Skip to main content

deep_causality_num/identity/
one.rs

1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5use core::ops::Mul;
6
7/// Defines a multiplicative identity element for `Self`.
8///
9/// # Laws
10///
11/// ```text
12/// a * 1 = a       ∀ a ∈ Self
13/// 1 * a = a       ∀ a ∈ Self
14/// ```
15pub trait One: Sized + Mul<Self, Output = Self> {
16    /// Returns the multiplicative identity element of `Self`, `1`.
17    ///
18    /// # Purity
19    ///
20    /// This function should return the same result at all times regardless of
21    /// external mutable state.
22    // This cannot be an associated constant, because of bignums.
23    fn one() -> Self;
24
25    /// Sets `self` to the multiplicative identity element of `Self`, `1`.
26    fn set_one(&mut self) {
27        *self = One::one();
28    }
29
30    /// Returns `true` if `self` is equal to the multiplicative identity.
31    fn is_one(&self) -> bool;
32}
33
34/// Defines an associated constant representing the multiplicative identity
35/// element for `Self`.
36pub trait ConstOne: One {
37    /// The multiplicative identity element of `Self`, `1`.
38    const ONE: Self;
39}