assembly_fdb_core/value/
mem.rs

1//! Values as stored in byte slices
2
3use latin1str::Latin1Str;
4
5use super::{Context, Value};
6
7#[derive(Debug, PartialEq, Eq)]
8/// The context for `mem::Field`
9pub struct MemContext<'a> {
10    _m: std::marker::PhantomData<fn() -> &'a ()>,
11}
12
13impl<'a> Context for MemContext<'a> {
14    type String = &'a Latin1Str;
15    type I64 = i64;
16    type XML = &'a Latin1Str;
17}
18
19/// Value of or reference to a field value
20pub type Field<'a> = Value<MemContext<'a>>;
21
22#[cfg(feature = "sqlite")]
23impl<'a> rusqlite::ToSql for Field<'a> {
24    fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
25        use rusqlite::types::ToSqlOutput;
26        use std::borrow::Cow;
27        Ok(match *self {
28            Field::Nothing => ToSqlOutput::Owned(rusqlite::types::Value::Null),
29            Field::Integer(i) => i.into(),
30            Field::Float(f) => f.into(),
31            Field::Boolean(b) => b.into(),
32            Field::BigInt(i) => i.into(),
33            Field::Text(s) | Field::VarChar(s) => match s.decode() {
34                Cow::Owned(s) => ToSqlOutput::from(s),
35                Cow::Borrowed(s) => ToSqlOutput::from(s),
36            },
37        })
38    }
39}