diff options
author | Cara Salter <cara@devcara.com> | 2022-05-29 23:10:58 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-05-29 23:10:58 -0400 |
commit | d64db7ab0a3180df867b931fb078ec820cb1c9d7 (patch) | |
tree | 8f28b2b0539c31ce165a1f8e482122d5bc277c6b /src/ship.rs | |
parent | bd1218eca88438d28afd4d171a2505ecc9c0bb23 (diff) | |
download | solarlib-d64db7ab0a3180df867b931fb078ec820cb1c9d7.tar.gz solarlib-d64db7ab0a3180df867b931fb078ec820cb1c9d7.zip |
ship: Add DbShip
Allows for easier querying from a database using, e.g, sqlx' `query_as!`
macro.
Diffstat (limited to 'src/ship.rs')
-rw-r--r-- | src/ship.rs | 25 |
1 files changed, 24 insertions, 1 deletions
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<DbShip> 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, |