deep_causality_num/identity/
zero.rs

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