feat: implement serialization and deserialiation for Gist, GIstPrivacy and GistComments in db_core

master
Aravinth Manivannan 2022-02-15 22:56:29 +05:30
parent 18865552e1
commit 44d920f6ea
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
3 changed files with 12 additions and 3 deletions

2
Cargo.lock generated
View File

@ -683,6 +683,8 @@ name = "db-core"
version = "0.1.0"
dependencies = [
"async-trait",
"serde 1.0.136",
"serde_json",
"thiserror",
]

View File

@ -15,7 +15,11 @@ authors = ["realaravinth <realaravinth@batsense.net>"]
[dependencies]
async-trait = "0.1.51"
thiserror = "1.0.30"
serde = { version = "1", features = ["derive"]}
[features]
default = []
test = []
[dev-dependencies]
serde_json = "1"

View File

@ -14,6 +14,8 @@
//! - [errors](crate::auth): error data structures used in this crate
//! - [ops](crate::ops): meta operations like connection pool creation, migrations and getting
//! connection from pool
use serde::{Deserialize, Serialize};
pub mod errors;
pub mod ops;
#[cfg(feature = "test")]
@ -66,7 +68,8 @@ pub struct CreateGist<'a> {
}
/// Gist visibility
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum GistVisibility {
/// Everyone can see the gist, will be displayed on /explore and
/// search engines might index it too
@ -109,7 +112,7 @@ impl From<GistVisibility> for String {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
/// Represents a gist
pub struct Gist {
/// owner of the gist
@ -126,7 +129,7 @@ pub struct Gist {
pub visibility: GistVisibility,
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
/// Represents a comment on a Gist
pub struct GistComment {
/// Unique identifier, possible database assigned, auto-incremented ID