pub trait Encode<'q, DB>where
DB: Database,{
// Required method
fn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>;
// Provided methods
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where Self: Sized { ... }
fn produces(&self) -> Option<<DB as Database>::TypeInfo> { ... }
fn size_hint(&self) -> usize { ... }
}Expand description
Encode a single value to be sent to the database.
Required Methods§
Sourcefn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Writes the value of self into buf without moving self.
Where possible, make use of encode instead as it can take advantage of re-using
memory.
Provided Methods§
Sourcefn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
Writes the value of self into buf in the expected format for the database.
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Encode<'_, MySql> for OffsetDateTime
impl Encode<'_, MySql> for OffsetDateTime
Source§impl Encode<'_, MySql> for PlainDateTime
impl Encode<'_, MySql> for PlainDateTime
Source§impl Encode<'_, Postgres> for &[u8]
impl Encode<'_, Postgres> for &[u8]
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for &str
impl Encode<'_, Postgres> for &str
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for OffsetDateTime
impl Encode<'_, Postgres> for OffsetDateTime
Source§impl Encode<'_, Postgres> for PlainDateTime
impl Encode<'_, Postgres> for PlainDateTime
Source§impl Encode<'_, Postgres> for SignedDuration
Available on crate feature time only.
impl Encode<'_, Postgres> for SignedDuration
time only.Source§impl Encode<'_, Postgres> for Vec<u8>
impl Encode<'_, Postgres> for Vec<u8>
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for bool
impl Encode<'_, Postgres> for bool
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for f32
impl Encode<'_, Postgres> for f32
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for f64
impl Encode<'_, Postgres> for f64
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for i8
impl Encode<'_, Postgres> for i8
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for i16
impl Encode<'_, Postgres> for i16
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for i32
impl Encode<'_, Postgres> for i32
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Postgres> for i64
impl Encode<'_, Postgres> for i64
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for &[u8]
impl Encode<'_, Sqlite> for &[u8]
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for &str
impl Encode<'_, Sqlite> for &str
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for Arc<[u8]>
impl Encode<'_, Sqlite> for Arc<[u8]>
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for Date
impl Encode<'_, Sqlite> for Date
fn encode_by_ref( &self, buf: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for OffsetDateTime
impl Encode<'_, Sqlite> for OffsetDateTime
fn encode_by_ref( &self, buf: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for PlainDateTime
impl Encode<'_, Sqlite> for PlainDateTime
fn encode_by_ref( &self, buf: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for Rc<[u8]>
impl Encode<'_, Sqlite> for Rc<[u8]>
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for Rc<str>
impl Encode<'_, Sqlite> for Rc<str>
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for Time
impl Encode<'_, Sqlite> for Time
fn encode_by_ref( &self, buf: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for bool
impl Encode<'_, Sqlite> for bool
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for f32
impl Encode<'_, Sqlite> for f32
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for f64
impl Encode<'_, Sqlite> for f64
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for i8
impl Encode<'_, Sqlite> for i8
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for i16
impl Encode<'_, Sqlite> for i16
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for i32
impl Encode<'_, Sqlite> for i32
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for i64
impl Encode<'_, Sqlite> for i64
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for u8
impl Encode<'_, Sqlite> for u8
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for u16
impl Encode<'_, Sqlite> for u16
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl Encode<'_, Sqlite> for u32
impl Encode<'_, Sqlite> for u32
fn encode_by_ref( &self, args: &mut SqliteArgumentsBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<i8>
impl<'q, DB> Encode<'q, DB> for NonZero<i8>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<i16>
impl<'q, DB> Encode<'q, DB> for NonZero<i16>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<i32>
impl<'q, DB> Encode<'q, DB> for NonZero<i32>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<i64>
impl<'q, DB> Encode<'q, DB> for NonZero<i64>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<u8>
impl<'q, DB> Encode<'q, DB> for NonZero<u8>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<u16>
impl<'q, DB> Encode<'q, DB> for NonZero<u16>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<u32>
impl<'q, DB> Encode<'q, DB> for NonZero<u32>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, DB> Encode<'q, DB> for NonZero<u64>
impl<'q, DB> Encode<'q, DB> for NonZero<u64>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Source§impl<'q, T, DB> Encode<'q, DB> for &T
impl<'q, T, DB> Encode<'q, DB> for &T
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl<'q, T, DB> Encode<'q, DB> for Arc<T>
impl<'q, T, DB> Encode<'q, DB> for Arc<T>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl<'q, T, DB> Encode<'q, DB> for Box<T>
impl<'q, T, DB> Encode<'q, DB> for Box<T>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl<'q, T, DB> Encode<'q, DB> for Cow<'q, T>
impl<'q, T, DB> Encode<'q, DB> for Cow<'q, T>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl<'q, T, DB> Encode<'q, DB> for Rc<T>
impl<'q, T, DB> Encode<'q, DB> for Rc<T>
fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl<'q, T, const N: usize> Encode<'q, Postgres> for [T; N]
impl<'q, T, const N: usize> Encode<'q, Postgres> for [T; N]
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl<'q, T> Encode<'q, MySql> for Option<T>
impl<'q, T> Encode<'q, MySql> for Option<T>
fn produces(&self) -> Option<<MySql as Database>::TypeInfo>
fn encode( self, buf: &mut <MySql as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <MySql as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn size_hint(&self) -> usize
Source§impl<'q, T> Encode<'q, Postgres> for &[T]
impl<'q, T> Encode<'q, Postgres> for &[T]
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl<'q, T> Encode<'q, Postgres> for Option<T>
impl<'q, T> Encode<'q, Postgres> for Option<T>
fn produces(&self) -> Option<<Postgres as Database>::TypeInfo>
fn encode( self, buf: &mut <Postgres as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <Postgres as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn size_hint(&self) -> usize
Source§impl<'q, T> Encode<'q, Postgres> for Vec<T>
impl<'q, T> Encode<'q, Postgres> for Vec<T>
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§impl<'q, T> Encode<'q, Sqlite> for Option<T>
impl<'q, T> Encode<'q, Sqlite> for Option<T>
fn produces(&self) -> Option<<Sqlite as Database>::TypeInfo>
fn encode( self, buf: &mut <Sqlite as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut <Sqlite as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn size_hint(&self) -> usize
Source§impl<const N: usize> Encode<'_, Postgres> for [u8; N]
impl<const N: usize> Encode<'_, Postgres> for [u8; N]
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Implementors§
impl Encode<'_, MySql> for BigDecimal
impl Encode<'_, MySql> for Hyphenated
impl Encode<'_, MySql> for MySqlTime
impl Encode<'_, MySql> for Simple
impl Encode<'_, MySql> for Uuid
Source§impl Encode<'_, Postgres> for BigDecimal
§Note: BigDecimal Has a Larger Range than NUMERIC
BigDecimal can represent values with a far, far greater range than the NUMERIC type in Postgres can.
impl Encode<'_, Postgres> for BigDecimal
§Note: BigDecimal Has a Larger Range than NUMERIC
BigDecimal can represent values with a far, far greater range than the NUMERIC type in Postgres can.
NUMERIC is limited to 131,072 digits before the decimal point, and 16,384 digits after it.
See Section 8.1, Numeric Types of the Postgres manual for details.
Meanwhile, BigDecimal can theoretically represent a value with an arbitrary number of decimal digits, albeit
with a maximum of 263 significant figures.
Because encoding in the current API design must be infallible,
when attempting to encode a BigDecimal that cannot fit in the wire representation of NUMERIC,
SQLx may instead encode a sentinel value that falls outside the allowed range but is still representable.
This will cause the query to return a DatabaseError with code 22P03 (invalid_binary_representation)
and the error message invalid scale in external "numeric" value (though this may be subject to change).
However, BigDecimal should be able to decode any NUMERIC value except NaN,
for which it has no representation.