Skip to main content

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(
        _value: Vec<PostgresValue<'_>>,
    ) -> Result<Self, DrizzleError> { ... }
}
Expand description

A Rust type that can be built from a PostgresValue.

There is one method per kind of stored value. The required ones cover booleans, integers, floats, text and bytes; the others (NULL, UUID, JSON, arrays, dates and times, network, geometric and bit types) default to an error, and some exist only with the matching feature. Implement the ones that make sense for your type and return an error from the rest.

This crate implements it for bool, all primitive integer types, f32, f64, strings, byte vectors, Option<T> (NULL becomes None), the optional crates’ types, and every PostgresEnum, so native enums from #[derive(PostgresEnum)] get it automatically. PostgresValue::convert dispatches to the right method.

Required Methods§

Source

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

Converts from a boolean value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Source

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

Converts from a 16-bit integer value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Source

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

Converts from a 32-bit integer value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Source

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

Converts from a 64-bit integer value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Source

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

Converts from a 32-bit float value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Source

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

Converts from a 64-bit float value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Source

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

Converts from a text/string value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Source

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

Converts from a binary/bytea value.

§Errors

Returns DrizzleError::ConversionError if the value cannot be represented as the target type.

Provided Methods§

Source

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

Converts from NULL. The default returns an error.

§Errors

Returns DrizzleError::ConversionError unless the implementor treats NULL as a valid value.

Source

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

Converts from an ARRAY value.

§Errors

Returns DrizzleError::ConversionError if the target type cannot represent an ARRAY value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FromPostgresValue for Arc<String>

Source§

impl FromPostgresValue for Arc<Vec<u8>>

Source§

impl FromPostgresValue for Arc<str>

Source§

impl FromPostgresValue for Box<String>

Source§

impl FromPostgresValue for Box<Vec<u8>>

Source§

impl FromPostgresValue for Box<str>

Source§

impl FromPostgresValue for Rc<String>

Source§

impl FromPostgresValue for Rc<Vec<u8>>

Source§

impl FromPostgresValue for Rc<str>

Source§

impl FromPostgresValue for String

Source§

impl FromPostgresValue for Vec<OwnedPostgresValue>

Source§

impl FromPostgresValue for Vec<PostgresValue<'_>>

Source§

impl FromPostgresValue for Vec<u8>

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<T: FromPostgresValue> FromPostgresValue for Option<T>

Implementors§