junobuild_shared/utils.rs
1use candid::Principal;
2
3/// Checks if two principals are not equal.
4///
5/// # Arguments
6/// * `x` - The first principal to compare.
7/// * `y` - The second principal to compare.
8///
9/// # Returns
10/// True if the principals are not equal; false otherwise.
11pub fn principal_not_equal(x: Principal, y: Principal) -> bool {
12 x != y
13}
14
15/// Checks if two principals are equal.
16///
17/// # Arguments
18/// * `x` - The first principal to compare.
19/// * `y` - The second principal to compare.
20///
21/// # Returns
22/// True if the principals are equal; false otherwise.
23pub fn principal_equal(x: Principal, y: Principal) -> bool {
24 x == y
25}
26
27/// Checks if a principal is not the anonymous principal.
28///
29/// # Arguments
30/// * `p` - The principal to check.
31///
32/// # Returns
33/// True if the principal is not anonymous; false otherwise.
34pub fn principal_not_anonymous(p: Principal) -> bool {
35 principal_not_equal(p, Principal::anonymous())
36}
37
38/// Checks if a principal is the anonymous principal.
39///
40/// # Arguments
41/// * `p` - The principal to check.
42///
43/// # Returns
44/// True if the principal is anonymous; false otherwise.
45pub fn principal_anonymous(p: Principal) -> bool {
46 principal_equal(p, Principal::anonymous())
47}
48
49/// Checks if two principals are equal and neither is anonymous.
50///
51/// # Arguments
52/// * `x` - The first principal to compare.
53/// * `y` - The second principal to compare.
54///
55/// # Returns
56/// True if the principals are equal and neither is anonymous; false otherwise.
57pub fn principal_not_anonymous_and_equal(x: Principal, y: Principal) -> bool {
58 principal_not_anonymous(x) && principal_equal(x, y)
59}