FromPostgresValue

Trait FromPostgresValue 

Source
pub trait FromPostgresValue: Sized {
    // Required methods
    fn from_postgres_bool(value: bool) -> Result<Self, DrizzleError>;
    fn from_postgres_i16(value: i16) -> Result<Self, DrizzleError>;
    fn from_postgres_i32(value: i32) -> Result<Self, DrizzleError>;
    fn from_postgres_i64(value: i64) -> Result<Self, DrizzleError>;
    fn from_postgres_f32(value: f32) -> Result<Self, DrizzleError>;
    fn from_postgres_f64(value: f64) -> Result<Self, DrizzleError>;
    fn from_postgres_text(value: &str) -> Result<Self, DrizzleError>;
    fn from_postgres_bytes(value: &[u8]) -> Result<Self, DrizzleError>;

    // Provided methods
    fn from_postgres_null() -> Result<Self, DrizzleError> { ... }
    fn from_postgres_array<'a>(
        _value: Vec<PostgresValue<'a>>,
    ) -> Result<Self, DrizzleError> { ... }
}
Expand description

Trait for types that can be converted from PostgreSQL values.

PostgreSQL has many types, but this trait focuses on the core conversions:

  • Integers (i16, i32, i64)
  • Floats (f32, f64)
  • Text (String, &str)
  • Binary (Vec, &u8)
  • Boolean
  • NULL handling

§Implementation Notes

  • Implement the methods that make sense for your type
  • Return Err for unsupported conversions
  • PostgresEnum derive automatically implements this trait

Required Methods§

Source

fn from_postgres_bool(value: bool) -> Result<Self, DrizzleError>

Convert from a boolean value

Source

fn from_postgres_i16(value: i16) -> Result<Self, DrizzleError>

Convert from a 16-bit integer value

Source

fn from_postgres_i32(value: i32) -> Result<Self, DrizzleError>

Convert from a 32-bit integer value

Source

fn from_postgres_i64(value: i64) -> Result<Self, DrizzleError>

Convert from a 64-bit integer value

Source

fn from_postgres_f32(value: f32) -> Result<Self, DrizzleError>

Convert from a 32-bit float value

Source

fn from_postgres_f64(value: f64) -> Result<Self, DrizzleError>

Convert from a 64-bit float value

Source

fn from_postgres_text(value: &str) -> Result<Self, DrizzleError>

Convert from a text/string value

Source

fn from_postgres_bytes(value: &[u8]) -> Result<Self, DrizzleError>

Convert from a binary/bytea value

Provided Methods§

Source

fn from_postgres_null() -> Result<Self, DrizzleError>

Convert from a NULL value (default returns error)

Source

fn from_postgres_array<'a>( _value: Vec<PostgresValue<'a>>, ) -> Result<Self, DrizzleError>

Convert from an ARRAY value

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromPostgresValue for bool

Source§

impl FromPostgresValue for f32

Source§

impl FromPostgresValue for f64

Source§

impl FromPostgresValue for i8

Source§

impl FromPostgresValue for i16

Source§

impl FromPostgresValue for i32

Source§

impl FromPostgresValue for i64

Source§

impl FromPostgresValue for isize

Source§

impl FromPostgresValue for u8

Source§

impl FromPostgresValue for u16

Source§

impl FromPostgresValue for u32

Source§

impl FromPostgresValue for u64

Source§

impl FromPostgresValue for usize

Source§

impl FromPostgresValue for String

Source§

impl FromPostgresValue for Vec<OwnedPostgresValue>

Source§

impl FromPostgresValue for Vec<u8>

Source§

impl<'a> FromPostgresValue for Vec<PostgresValue<'a>>

Source§

impl<T: FromPostgresValue> FromPostgresValue for Option<T>

Implementors§