summaryrefslogtreecommitdiff
path: root/src/api/mod.rs
blob: 1831659730e28a147d12806c3971990af1851263 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use chrono::{DateTime, TimeZone};
use rocket::serde::json::Json;
use serde::{Deserialize, Serialize, Serializer};

pub(crate) mod auth;
pub(crate) mod oauth;
pub(crate) mod profile;

pub fn serialize_dt<S, TZ>(dt: &DateTime<TZ>, ser: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
    TZ: TimeZone,
{
    ser.serialize_i64(dt.timestamp())
}

pub fn serialize_dt_opt<S, TZ>(dt: &Option<DateTime<TZ>>, ser: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,
    TZ: TimeZone,
{
    match dt {
        Some(dt) => serialize_dt(dt, ser),
        None => ser.serialize_unit(),
    }
}

#[derive(Clone, Copy, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Empty {}

pub const EMPTY: Json<Empty> = Json(Empty {});