diesel/pg/types/
json_function_enum.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::error::Error;
use std::io::Write;

use crate::pg::Pg;
use crate::serialize::{self, IsNull, Output, ToSql};
use crate::sql_types::*;

#[cfg(feature = "postgres_backend")]
impl ToSql<NullValueTreatmentEnum, Pg> for NullValueTreatment {
    fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
        let literal = match self {
            Self::RaiseException => "raise_exxception",
            Self::UseJsonNull => "use_json_null",
            Self::DeleteKey => "delete_key",
            Self::ReturnTarget => "return_target",
        };
        out.write_all(literal.as_bytes())
            .map(|_| IsNull::No)
            .map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
    }
}