Newer
Older
}
// Implementations for unsigned integer types
impl IntoTile for u8 {
}
// Implementations for signed integer types
impl IntoTile for i8 {
}
// We don't actually implement IntoTile for TileStatus, as this would conflict with a later From impl
impl TileStatus {
pub fn into_tile(self) -> i32 {
match self {
Self::Ignore => 0,
Self::Nothing => -1000001,
Self::Anything => 1000001,
Self::Is(value) => value,
Self::IsNot(value) => -(value),
}
}
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
fn from(value: TileStatus) -> Self {
value.into_tile() as i64
}
}
impl<T: IntoTile> IntoTile for Option<T> {
fn into_tile(self) -> i32 {
match self {
Some(value) => value.into_tile(),
None => 0,
}
}
}
impl<T: IntoTile, E> IntoTile for Result<T, E> {
fn into_tile(self) -> i32 {
match self {
Ok(value) => value.into_tile(),
Err(_) => 0,
}
}
}
impl<I: IntoTile> From<I> for TileStatus {
fn from(value: I) -> Self {
let value = value.into_tile();
match value {
0 => Self::Ignore,
1000001 => Self::Anything,
-1000001 => Self::Nothing,
other => {
if other > 0 {
Self::Is(other.into_tile())
} else {
Self::IsNot(other.abs().into_tile())
}
}
}
}
}