Skip to main content

ToWireValue

Trait ToWireValue 

Source
pub trait ToWireValue {
    // Required methods
    fn natural_oid(&self) -> Oid;
    fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>;
}
Expand description

Trait for encoding Rust values as PostgreSQL parameters.

Implementations write length-prefixed data directly to the buffer:

  • Int32 length followed by the value bytes, OR
  • Int32 -1 for NULL

The trait provides OID-aware encoding:

  • natural_oid() returns the OID this value naturally encodes to
  • encode() encodes the value for a specific target OID, using the preferred format (text for NUMERIC, binary for everything else)

Required Methods§

Source

fn natural_oid(&self) -> Oid

The OID this value naturally encodes to.

For example, i64 naturally encodes to INT8 (OID 20).

Source

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Encode this value for the given target OID.

This allows flexible encoding: an i64 can encode as INT2, INT4, or INT8 depending on what the server expects (with overflow checking).

The format (text vs binary) is determined by preferred_format(target_oid):

  • NUMERIC uses text format (decimal string representation)
  • All other types use binary format

The implementation should write:

  • 4-byte length (i32, big-endian)
  • followed by the encoded data

For NULL values, write -1 as the length (no data follows).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl ToWireValue for String

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for Vec<u8>

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for [u8]

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for bool

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for f32

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for f64

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for i8

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for i16

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for i32

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for i64

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for str

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for u8

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for u16

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for u32

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl ToWireValue for u64

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl<T: ToWireValue + ?Sized> ToWireValue for &T

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Source§

impl<T: ToWireValue> ToWireValue for Option<T>

Source§

fn natural_oid(&self) -> Oid

Source§

fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>

Implementors§