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§
Sourcetype EncodedKey: PostgresKey
type EncodedKey: PostgresKey
PostgreSQL representation of the key column.
Sourcetype EncodedValue: PostgresValue
type EncodedValue: PostgresValue
PostgreSQL representation of the value column.
Required Methods§
Sourcefn encode_key(&self, key: &K) -> Result<Self::EncodedKey, PostgresBackendError>
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.
Sourcefn encode_value(
&self,
value: &V,
) -> Result<Self::EncodedValue, PostgresBackendError>
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.
Sourcefn decode_value(
&self,
value: Self::EncodedValue,
) -> Result<V, PostgresBackendError>
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".