pub struct TableWriterBuilder { /* private fields */ }
Expand description

Builder to be used to create a TableWriter.

The dBase format is akin to a database, thus you have to specify the fields of the record you are going to write

Example

Here we will create a writer that will be able to write records with 2 character fields where both fields cannot exceed 50 bytes in length.

The writer will write its data to a cursor, but files are also supported.

use dbase::{TableWriterBuilder, FieldName};
use std::convert::TryFrom;
use std::io::Cursor;

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

Implementations§

source§

impl TableWriterBuilder

source

pub fn new() -> Self

Creates a new builder with an empty dBase record definition

Sets the encoding to UnicodeLossy

source

pub fn with_encoding<E: Encoding + 'static>(encoding: E) -> Self

Creates a new builder with an empty dBase record definition with the given encoding

source

pub fn from_reader<T: Read + Seek>(reader: Reader<T>) -> Self

Gets the field definition from the reader to construct the TableWriter

Example
use dbase::{FieldValue, TableWriterBuilder};
use std::io::Cursor;
let mut  reader = dbase::Reader::from_path("tests/data/stations.dbf").unwrap();
let mut stations = reader.read().unwrap();
let old_name = stations[0].insert("name".parse().unwrap(), String::from("Montparnasse").into());
assert_eq!(old_name, Some(FieldValue::Character(Some("Van Dorn Street".parse().unwrap()))));

let mut writer = TableWriterBuilder::from_reader(reader)
    .build_with_dest(Cursor::new(Vec::<u8>::new()));

// from_reader picked up the record definition,
// so writing will work
let writing_result = writer.write_records(&stations);
assert_eq!(writing_result.is_ok(), true);
source

pub fn from_table_info(table_info: TableInfo) -> Self

source

pub fn set_encoding<E: Encoding + 'static>(self, encoding: E) -> Self

Changes the encoding of the writer.

source

pub fn add_character_field(self, name: FieldName, length: u8) -> Self

Adds a Character field to the record definition, the length is the maximum number of bytes (not chars) that fields can hold

source

pub fn add_date_field(self, name: FieldName) -> Self

Adds a Date field

source

pub fn add_numeric_field( self, name: FieldName, length: u8, num_decimals: u8 ) -> Self

Adds a Numeric

source

pub fn add_float_field( self, name: FieldName, length: u8, num_decimals: u8 ) -> Self

Adds a Float

source

pub fn add_logical_field(self, name: FieldName) -> Self

Adds a Logical

source

pub fn add_integer_field(self, name: FieldName) -> Self

Adds a Integer

source

pub fn add_datetime_field(self, name: FieldName) -> Self

Adds a DateTime

source

pub fn add_double_field(self, name: FieldName) -> Self

Adds a Double

source

pub fn add_currency_field(self, name: FieldName) -> Self

Adds a Currency

source

pub fn build_with_dest<W: Write + Seek>(self, dst: W) -> TableWriter<W>

Builds the writer and set the dst as where the file data will be written

source

pub fn build_with_file_dest<P: AsRef<Path>>( self, path: P ) -> Result<TableWriter<BufWriter<File>>, Error>

Helper function to set create a file at the given path and make the writer write to the newly created file.

This function wraps the File in a BufWriter to increase performance.

source

pub fn build_table_info(self) -> TableInfo

Auto Trait Implementations§

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>,

§

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>,

§

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.