Start backend with rocket.rs
This commit is contained in:
1
rs/.gitignore
vendored
Normal file
1
rs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target/
|
||||||
1350
rs/Cargo.lock
generated
Normal file
1350
rs/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
rs/Cargo.toml
Normal file
10
rs/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "schach"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rocket = { version = "0.5.0-rc.1", features = ["json"] }
|
||||||
|
serde = "1.0.127"
|
||||||
20
rs/src/main.rs
Normal file
20
rs/src/main.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#[macro_use]
|
||||||
|
extern crate rocket;
|
||||||
|
use rocket::serde::{json::Json, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct Greeting<'a> {
|
||||||
|
hello: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
fn index() -> Json<Greeting<'static>> {
|
||||||
|
Json(Greeting {
|
||||||
|
hello: "Hello, world!",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[launch]
|
||||||
|
fn rocket() -> _ {
|
||||||
|
rocket::build().mount("/api/", routes![index])
|
||||||
|
}
|
||||||
59
rs/src/pieces.rs
Normal file
59
rs/src/pieces.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
enum PieceKind {
|
||||||
|
Rook,
|
||||||
|
Knight,
|
||||||
|
Bishop,
|
||||||
|
King,
|
||||||
|
Queen,
|
||||||
|
Pawn,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum PieceColor {
|
||||||
|
Black,
|
||||||
|
White,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Column {
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
D,
|
||||||
|
E,
|
||||||
|
F,
|
||||||
|
G,
|
||||||
|
H,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Row {
|
||||||
|
_1,
|
||||||
|
_2,
|
||||||
|
_3,
|
||||||
|
_4,
|
||||||
|
_5,
|
||||||
|
_6,
|
||||||
|
_7,
|
||||||
|
_8,
|
||||||
|
}
|
||||||
|
|
||||||
|
type Position = (Column, Row);
|
||||||
|
|
||||||
|
struct Piece {
|
||||||
|
kind: PieceKind,
|
||||||
|
color: PieceColor,
|
||||||
|
position: Position,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Board {
|
||||||
|
pieces: Vec<Piece>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Board {
|
||||||
|
fn fresh() -> Board {
|
||||||
|
Board {
|
||||||
|
pieces: vec![Piece {
|
||||||
|
kind: PieceKind::Rook,
|
||||||
|
color: PieceColor::Black,
|
||||||
|
position: (Column::A, Row::_8),
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user