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>
impl<W: Write + Seek> TableWriter<W>
Sourcepub fn write_record<R: WritableRecord>(
&mut self,
record: &R,
) -> Result<(), Error>
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(())Sourcepub fn write_records<'a, R: WritableRecord + 'a, C: IntoIterator<Item = &'a R>>(
self,
records: C,
) -> Result<(), Error>
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)Sourcepub fn finalize(&mut self) -> Result<(), Error>
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
pub fn close(&mut self) -> Result<(), Error>
👎Deprecated: Use finalize instead
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more