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
43
44
45
46
47
use super::SerializationError;

/// A factory for database objects.
///
/// This trait is ot be implemented by descriptors of parameters for database commands.
///
/// # Example
///
/// A parameter descriptor for a String-valued database type might implement all
/// methods with adequate conversions, while a parameter descriptor for an integer type might
/// only support conversions from the rust integer types.
pub trait DbvFactory: Sized {
    /// The type of the database objects.
    type DBV;
    /// Serialize a bool.
    fn from_bool(&self, value: bool) -> Result<Self::DBV, SerializationError>;
    /// Serialize an i8.
    fn from_i8(&self, value: i8) -> Result<Self::DBV, SerializationError>;
    /// Serialize an i16.
    fn from_i16(&self, value: i16) -> Result<Self::DBV, SerializationError>;
    /// Serialize an i32.
    fn from_i32(&self, value: i32) -> Result<Self::DBV, SerializationError>;
    /// Serialize an i64.
    fn from_i64(&self, value: i64) -> Result<Self::DBV, SerializationError>;
    /// Serialize an u8.
    fn from_u8(&self, value: u8) -> Result<Self::DBV, SerializationError>;
    /// Serialize an u16.
    fn from_u16(&self, value: u16) -> Result<Self::DBV, SerializationError>;
    /// Serialize an u32.
    fn from_u32(&self, value: u32) -> Result<Self::DBV, SerializationError>;
    /// Serialize an u64.
    fn from_u64(&self, value: u64) -> Result<Self::DBV, SerializationError>;
    /// Serialize an f32.
    fn from_f32(&self, value: f32) -> Result<Self::DBV, SerializationError>;
    /// Serialize an f64.
    fn from_f64(&self, value: f64) -> Result<Self::DBV, SerializationError>;
    /// Serialize a char.
    fn from_char(&self, value: char) -> Result<Self::DBV, SerializationError>;
    /// Serialize a str.
    fn from_str(&self, value: &str) -> Result<Self::DBV, SerializationError>;
    /// Serialize bytes.
    fn from_bytes(&self, value: &[u8]) -> Result<Self::DBV, SerializationError>;
    /// Serialize a none.
    fn from_none(&self) -> Result<Self::DBV, SerializationError>;
    /// Provide a descriptive String of the type that is required (for error messages).
    fn descriptor(&self) -> &'static str;
}