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
33
34
35
36
37
38
39
40
41
42
use crate::database::Database;
use bitflags::_core::fmt::Debug;
use crate::Result;
use crate::types::chrono::NaiveDateTime;
use chrono::Local;

/// Associate [`Database`] with a `RawValue` of a generic lifetime.

///

/// ---

///

/// The upcoming Rust feature, [Generic Associated Types], should obviate

/// the need for this trait.

///

/// [Generic Associated Types]: https://www.google.com/search?q=generic+associated+types+rust&oq=generic+associated+types+rust&aqs=chrome..69i57j0l5.3327j0j7&sourceid=chrome&ie=UTF-8

pub trait HasRawValue<'c> {
    type Database: Database;

    /// The Rust type used to hold a not-yet-decoded value that has just been

    /// received from the database.

    type RawValue: RawValue<'c, Database = Self::Database>+Debug;
}

pub trait RawValue<'c> {
    type Database: Database;

    fn type_info(&self) -> Option<<Self::Database as Database>::TypeInfo>;

    /// to an json value

    fn try_to_json(&self) -> Result<serde_json::Value>;
}


pub trait DateTimeNow{
    fn now()->NaiveDateTime;
}

impl DateTimeNow for NaiveDateTime{
    fn now() -> NaiveDateTime {
        let dt = Local::now();
        dt.naive_local()
    }
}