Skip to main content

Encode

Trait Encode 

Source
pub trait Encode {
    // Required methods
    fn encode_binary(&self, buf: &mut Vec<u8>);
    fn type_oid(&self) -> u32;

    // Provided methods
    fn is_null(&self) -> bool { ... }
    fn encode_at(&self, dst: &mut [u8]) -> bool { ... }
}
Expand description

Encode a Rust value into PostgreSQL binary format.

Implementations append the binary representation to buf. The length prefix is handled by the caller (wire protocol layer), not the encoder.

§Example

use bsql_driver_postgres::Encode;

let mut buf = Vec::new();
42i32.encode_binary(&mut buf);
assert_eq!(buf, &[0, 0, 0, 42]);

Required Methods§

Source

fn encode_binary(&self, buf: &mut Vec<u8>)

Append the binary-encoded value to buf.

Source

fn type_oid(&self) -> u32

The PostgreSQL OID for this type.

Provided Methods§

Source

fn is_null(&self) -> bool

Whether this value represents SQL NULL.

When true, the wire protocol sends length -1 with no data bytes. Default is false. Implementations for Option<T> override this.

Source

fn encode_at(&self, dst: &mut [u8]) -> bool

Encode the binary value directly into dst at position 0.

Returns true if the encoded length matches dst.len() (i.e., same size as the template slot). Returns false if the size differs, signaling the caller to fall back to a full rebuild.

The default implementation uses a small inline buffer and copies. Fixed-size types (i32, i64, etc.) override this to write directly — eliminating the scratch buffer double-copy on the bind-template hot path.

Implementations on Foreign Types§

Source§

impl Encode for &str

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for &[&str]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[&[u8]]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[bool]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[f32]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[f64]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[i16]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[i32]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[i64]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[u8]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for &[String]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for &[Vec<u8>]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for bool

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for f32

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for f64

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for i16

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for i32

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for i64

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for u32

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for String

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for Vec<bool>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for Vec<f32>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for Vec<f64>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for Vec<i16>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for Vec<i32>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for Vec<i64>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for Vec<u8>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn encode_at(&self, dst: &mut [u8]) -> bool

Source§

impl Encode for Vec<String>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for Vec<Vec<u8>>

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [&str]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [&[u8]]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [bool]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [f32]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [f64]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [i16]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [i32]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [i64]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [String]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl Encode for [Vec<u8>]

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

impl<T> Encode for Option<T>
where T: Encode,

Source§

fn encode_binary(&self, buf: &mut Vec<u8>)

Source§

fn type_oid(&self) -> u32

Source§

fn is_null(&self) -> bool

Implementors§