TableWriter

Struct TableWriter 

Source
pub struct TableWriter<W: Write + Seek> { /* private fields */ }
Expand description

Structs that writes dBase records to a destination

The only way to create a TableWriter is to use its TableWriterBuilder

Implementations§

Source§

impl<W: Write + Seek> TableWriter<W>

Source

pub fn write_record<R: WritableRecord>( &mut self, record: &R, ) -> Result<(), Error>

Writes a record the inner destination

§Example
use std::convert::TryFrom;

let mut writer = dbase::TableWriterBuilder::new()
    .add_character_field(dbase::FieldName::try_from("First Name").unwrap(), 50)
    .build_with_file_dest("records.dbf")?;

let mut record = dbase::Record::default();
record.insert("First Name".to_string(), dbase::FieldValue::Character(Some("Yoshi".to_string())));

writer.write_record(&record)?;

Ok(())
Source

pub fn write_records<'a, R: WritableRecord + 'a, C: IntoIterator<Item = &'a R>>( self, records: C, ) -> Result<(), Error>

Writes the records to the inner destination

Values for which the number of bytes written would exceed the specified field_length (if it had to be specified) will be truncated

§Example
use dbase::{TableWriterBuilder, FieldName, WritableRecord, FieldWriter, ErrorKind, FieldIOError, Encoding};
use std::convert::TryFrom;
use std::io::{Cursor, Write};

struct User {
    first_name: String,
}

impl WritableRecord for User {
    fn write_using<'a, W>(&self,field_writer: &mut FieldWriter<'a, W>) -> Result<(), FieldIOError>
        where W: Write {
        field_writer.write_next_field_value(&self.first_name)
    }
}

let mut cursor = Cursor::new(Vec::<u8>::new());
let writer = TableWriterBuilder::new()
    .add_character_field(FieldName::try_from("First Name").unwrap(), 50)
    .build_with_dest(&mut cursor);

let records = vec![
    User {
        first_name: "Yoshi".to_owned(),
    }
];
writer.write_records(&records).unwrap();
assert_eq!(cursor.position(), 117)
Source

pub fn finalize(&mut self) -> Result<(), Error>

Finalize the writer

The writer is automatically closed when the writer is dropped, use it if you want to handle error that can happen when the writer is closing

Calling finalize on an already finalize writer is a no-op

Source

pub fn close(&mut self) -> Result<(), Error>

👎Deprecated: Use finalize instead

Trait Implementations§

Source§

impl<T: Write + Seek> Drop for TableWriter<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<W> Freeze for TableWriter<W>
where W: Freeze,

§

impl<W> !RefUnwindSafe for TableWriter<W>

§

impl<W> Send for TableWriter<W>
where W: Send,

§

impl<W> !Sync for TableWriter<W>

§

impl<W> Unpin for TableWriter<W>
where W: Unpin,

§

impl<W> !UnwindSafe for TableWriter<W>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.