[−][src]Struct pgcopy::Encoder
Low-level encoder for binary format.
End users are required to manually call all necessary methods in a right order.
use pgcopy::Encoder; let mut buf: Vec<u8> = vec![]; let mut encoder = Encoder::new(&mut buf); encoder.write_header().unwrap(); encoder.write_tuple(3).unwrap(); // First tuple with three columns encoder.write_smallint(1).unwrap(); // First column encoder.write_bool(false).unwrap(); // Second encoder.write_str("first").unwrap(); // Third encoder.write_tuple(3).unwrap(); // Second tuple encoder.write_smallint(2).unwrap(); encoder.write_bool(true).unwrap(); encoder.write_str("second").unwrap(); encoder.write_trailer().unwrap(); println!("{:?}", encoder.get_ref());
Methods
impl<W> Encoder<W> where
W: Write,
[src]
W: Write,
pub fn new(writer: W) -> Encoder<W>
[src]
Creates new encoder.
pub fn get_ref(&self) -> &W
[src]
Acquires a reference to the underlying writer.
pub fn get_mut(&mut self) -> &mut W
[src]
Acquires a mutable reference to the underlying writer.
Note that mutating the output/input state of the stream may corrupt this object, so care must be taken when using this method.
pub fn write_header(&mut self) -> Result<()>
[src]
Writes binary format header.
Caller is required to invoke this method first before starting to write tuples data.
pub fn write_trailer(&mut self) -> Result<()>
[src]
Writes binary format trailer.
Caller is required to invoke this method last immediately after writing tuples data.
pub fn write_tuple(&mut self, fields: i16) -> Result<()>
[src]
Starts a new tuple.
Each tuple begins with a signed 16-bit integer count of the number of fields in the tuple. Presently, all tuples in a table will have the same count.
pub fn write_null(&mut self) -> Result<()>
[src]
Writes NULL
as a column value.
pub fn write_smallint(&mut self, value: i16) -> Result<()>
[src]
Writes smallint
type value.
pub fn write_int(&mut self, value: i32) -> Result<()>
[src]
Writes int
type value.
pub fn write_bigint(&mut self, value: i64) -> Result<()>
[src]
Writes bigint
type value.
pub fn write_real(&mut self, value: f32) -> Result<()>
[src]
Writes real
type value.
pub fn write_double(&mut self, value: f64) -> Result<()>
[src]
Writes double precision
type value.
pub fn write_str<T: AsRef<str>>(&mut self, value: T) -> Result<()>
[src]
Writes character type value.
Any of character varying(n)
, character(n)
or text
column type should be handled by this method.
pub fn write_bytea<T: AsRef<[u8]>>(&mut self, value: T) -> Result<()>
[src]
Writes bytea
type value.
pub fn write_timestamp<T: Timestamp>(&mut self, value: T) -> Result<()>
[src]
Writes timestamp
type value.
See Timestamp type implementors for available options here.
pub fn write_timestamp_with_time_zone<T: TimestampWithTimeZone>(
&mut self,
value: T
) -> Result<()>
[src]
&mut self,
value: T
) -> Result<()>
Writes timestamp with time zone
type value.
See TimestampWithTimeZone type implementors for available options here.
pub fn write_date<T: Date>(&mut self, value: T) -> Result<()>
[src]
Writes date
type value.
See Date type implementors for available options here.
pub fn write_time<T: Time>(&mut self, value: T) -> Result<()>
[src]
Writes time
type value.
See Time type implementors for available options here.
pub fn write_bool<T: Into<bool>>(&mut self, value: T) -> Result<()>
[src]
Writes bool
type value.
pub fn write_uuid<T: Uuid>(&mut self, value: T) -> Result<()>
[src]
Writes uuid
type value.
See Uuid type implementors for available options here.
Trait Implementations
impl<W: Clone + Write> Clone for Encoder<W>
[src]
fn clone(&self) -> Encoder<W>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<W: Debug + Write> Debug for Encoder<W>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,