1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#[derive(Debug, Clone, Copy, Default, PartialEq)]
#[cfg_attr(feautre = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Zero;
#[derive(Debug, Clone, Copy, Default, PartialEq)]
#[cfg_attr(feautre = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NonZero;
pub trait ZeroChoice {}
impl ZeroChoice for Zero {}
impl ZeroChoice for NonZero {}
pub trait DecideZero<ZZ> {
type Out;
}
impl<Z: ZeroChoice> DecideZero<Z> for Zero {
type Out = Zero;
}
impl<Z: ZeroChoice> DecideZero<Z> for NonZero {
type Out = Z;
}
mod change_marks {
use crate::{marker::*, Point, Scalar};
impl<Z, S> ChangeMark<Scalar<S, Z>> for NonZero {
type Out = Option<Scalar<S, NonZero>>;
fn change_mark(scalar: Scalar<S, Z>) -> Self::Out {
if scalar.is_zero() {
None
} else {
Some(Scalar::from_inner(scalar.0))
}
}
}
impl<Z, S, T> ChangeMark<Point<T, S, Z>> for NonZero {
type Out = Option<Point<T, S, NonZero>>;
fn change_mark(point: Point<T, S, Z>) -> Self::Out {
if point.is_zero() {
None
} else {
Some(Point::from_inner(point.0, point.1))
}
}
}
impl<Z, S, Y> ChangeMark<Point<Y, S, Z>> for Zero {
type Out = Point<Y, S, Zero>;
fn change_mark(point: Point<Y, S, Z>) -> Self::Out {
Point::from_inner(point.0, point.1)
}
}
impl<Z, S> ChangeMark<Scalar<S, Z>> for Zero {
type Out = Scalar<S, Zero>;
fn change_mark(scalar: Scalar<S, Z>) -> Self::Out {
Scalar::from_inner(scalar.0)
}
}
}