Seems to be alright at deserialising the things so far
This commit is contained in:
@@ -7,3 +7,4 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.138"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize};
|
||||
|
||||
// Info from here:
|
||||
// https://scryfall.com/docs/api/cards
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct ScryfallCard {
|
||||
// Core Card Fields
|
||||
pub arena_id: Option<u64>,
|
||||
@@ -31,7 +31,7 @@ struct ScryfallCard {
|
||||
|
||||
// https://scryfall.com/docs/api/cards#card-face-objects
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct ScryfallCardFaceObject {
|
||||
pub artist: Option<String>,
|
||||
pub artist_id: Option<String>, // UUID
|
||||
@@ -45,7 +45,7 @@ struct ScryfallCardFaceObject {
|
||||
|
||||
// https://scryfall.com/docs/api/cards#related-card-objects
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct ScryfallRelatedCardObject {
|
||||
pub id: String, // UUID
|
||||
pub object: String, // Always "related_card"
|
||||
@@ -55,25 +55,37 @@ struct ScryfallRelatedCardObject {
|
||||
pub uri: String // URI
|
||||
}
|
||||
|
||||
#[derive(Deserialize, PartialEq)]
|
||||
#[derive(Deserialize, PartialEq, Debug)]
|
||||
enum Colour {
|
||||
#[serde(rename = "W")]
|
||||
White,
|
||||
#[serde(rename = "U")]
|
||||
Blue,
|
||||
#[serde(rename = "B")]
|
||||
Black,
|
||||
#[serde(rename = "R")]
|
||||
Red,
|
||||
#[serde(rename = "G")]
|
||||
Green,
|
||||
Colourless
|
||||
//#[serde(rename = "C")]
|
||||
// Colourless
|
||||
// Just realised that colourless is just an empty vector... probably need a custom deserialiser,
|
||||
// or just handle it at a higher level... probably just that - the caller/user can figure it out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn deserialise_nissa() {
|
||||
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
d.push("test_files/nissa.json");
|
||||
assert!(d.exists());
|
||||
let mut f = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
f.push("test_files/nissa.json");
|
||||
assert!(f.exists());
|
||||
let fc = fs::read_to_string(f).unwrap();
|
||||
let nissa: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
println!("{:#?}", nissa);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user