From d64db7ab0a3180df867b931fb078ec820cb1c9d7 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sun, 29 May 2022 23:10:58 -0400 Subject: ship: Add DbShip Allows for easier querying from a database using, e.g, sqlx' `query_as!` macro. --- src/ship.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/ship.rs') diff --git a/src/ship.rs b/src/ship.rs index 79253e1..bcb6981 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -10,7 +10,7 @@ use crate::{errors::Error, star::Star}; use serde::{Serialize, Deserialize}; /// Describes a hash of a file -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct Sha256(pub String); impl FromStr for Sha256 { @@ -41,6 +41,29 @@ pub struct Ship { pub version: String, } +/// Describes a starship generated from a database +#[derive(Serialize, Deserialize, Debug)] +pub struct DbShip { + /// The Database ID of the ship + pub id: i32, + + pub name: String, + pub shasum: Sha256, + pub download_url: String, + pub version: String +} + +impl From for Ship { + fn from(o: DbShip) -> Self { + Self { + name: o.name, + shasum: o.shasum, + download_url: o.download_url, + version: o.version + } + } +} + impl Ship { pub fn new(name: String, shasum: String, -- cgit v1.2.3