Skip to main content

PostgresCodec

Trait PostgresCodec 

Source
pub trait PostgresCodec<K, V>:
    Send
    + Sync
    + 'static {
    type EncodedKey: PostgresKey;
    type EncodedValue: PostgresValue;

    // Required methods
    fn encode_key(
        &self,
        key: &K,
    ) -> Result<Self::EncodedKey, PostgresBackendError>;
    fn encode_value(
        &self,
        value: &V,
    ) -> Result<Self::EncodedValue, PostgresBackendError>;
    fn decode_value(
        &self,
        value: Self::EncodedValue,
    ) -> Result<V, PostgresBackendError>;
}
Expand description

Encodes typed keys and values for application-owned PostgreSQL columns.

The associated representations determine the required column types. Use String for TEXT and Vec<u8> for BYTEA.

Required Associated Types§

Source

type EncodedKey: PostgresKey

PostgreSQL representation of the key column.

Source

type EncodedValue: PostgresValue

PostgreSQL representation of the value column.

Required Methods§

Source

fn encode_key(&self, key: &K) -> Result<Self::EncodedKey, PostgresBackendError>

Encodes a typed key.

§Errors

Returns a backend error whose source is the codec error when the key cannot be represented.

Source

fn encode_value( &self, value: &V, ) -> Result<Self::EncodedValue, PostgresBackendError>

Encodes a typed value.

§Errors

Returns a backend error whose source is the codec error when the value cannot be represented.

Source

fn decode_value( &self, value: Self::EncodedValue, ) -> Result<V, PostgresBackendError>

Decodes a typed value.

§Errors

Returns a backend error whose source is the codec error when the stored value is invalid.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§