Include a serde feature in the shared crate
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
3d93bf0fda
commit
f1962503b8
@ -1,134 +0,0 @@
|
||||
use board_shared::{
|
||||
board::Board,
|
||||
position::{Grid2d, Position2d},
|
||||
tile::{Digit, Operator, Tile},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct BoardRef {
|
||||
pub tiles: Vec<Option<TileRef>>,
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub enum TileRef {
|
||||
Digit(DigitRef),
|
||||
Operator(OperatorRef),
|
||||
Equals,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub struct DigitRef {
|
||||
pub value: i8,
|
||||
pub has_left_parenthesis: bool,
|
||||
pub has_right_parenthesis: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub enum OperatorRef {
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub struct Position2dRef {
|
||||
pub x: usize,
|
||||
pub y: usize,
|
||||
}
|
||||
|
||||
impl From<&Board> for BoardRef {
|
||||
fn from(value: &Board) -> Self {
|
||||
Self {
|
||||
tiles: value
|
||||
.iter()
|
||||
.map(|tile| tile.map(Into::into))
|
||||
.collect::<Vec<_>>(),
|
||||
width: value.width(),
|
||||
height: value.height(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Tile> for TileRef {
|
||||
fn from(value: Tile) -> Self {
|
||||
match value {
|
||||
Tile::Digit(digit) => TileRef::Digit(digit.into()),
|
||||
Tile::Operator(operator) => TileRef::Operator(operator.into()),
|
||||
Tile::Equals => TileRef::Equals,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TileRef> for Tile {
|
||||
fn from(value: TileRef) -> Self {
|
||||
match value {
|
||||
TileRef::Digit(digit) => Tile::Digit(digit.into()),
|
||||
TileRef::Operator(operator) => Tile::Operator(operator.into()),
|
||||
TileRef::Equals => Tile::Equals,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Digit> for DigitRef {
|
||||
fn from(value: Digit) -> Self {
|
||||
Self {
|
||||
value: value.value,
|
||||
has_left_parenthesis: value.has_left_parenthesis,
|
||||
has_right_parenthesis: value.has_right_parenthesis,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DigitRef> for Digit {
|
||||
fn from(value: DigitRef) -> Self {
|
||||
Self {
|
||||
value: value.value,
|
||||
has_left_parenthesis: value.has_left_parenthesis,
|
||||
has_right_parenthesis: value.has_right_parenthesis,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Operator> for OperatorRef {
|
||||
fn from(value: Operator) -> Self {
|
||||
match value {
|
||||
Operator::Add => OperatorRef::Add,
|
||||
Operator::Subtract => OperatorRef::Subtract,
|
||||
Operator::Multiply => OperatorRef::Multiply,
|
||||
Operator::Divide => OperatorRef::Divide,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OperatorRef> for Operator {
|
||||
fn from(value: OperatorRef) -> Self {
|
||||
match value {
|
||||
OperatorRef::Add => Operator::Add,
|
||||
OperatorRef::Subtract => Operator::Subtract,
|
||||
OperatorRef::Multiply => Operator::Multiply,
|
||||
OperatorRef::Divide => Operator::Divide,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Position2d> for Position2dRef {
|
||||
fn from(value: Position2d) -> Self {
|
||||
Self {
|
||||
x: value.x,
|
||||
y: value.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Position2dRef> for Position2d {
|
||||
fn from(value: Position2dRef) -> Self {
|
||||
Self {
|
||||
x: value.x,
|
||||
y: value.y,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue