pub struct File<T> { /* private fields */ }
Expand description
Handle to a dBase File.
A File
, allows to both read and write, it also
allows to do modifications on an existing file,
and enables to only read/modify parts of a file without
first having to fully read it.
Example
let mut file = dbase::File::open_read_only("tests/data/stations.dbf")?;
assert_eq!(file.num_records(), 86);
let name_idx = file.field_index("name").unwrap();
let marker_color_idx = file.field_index("marker-col").unwrap();
let marker_symbol_idx = file.field_index("marker-sym").unwrap();
// Test manually reading fields (not in correct order) to FieldValue
let mut rh = file.record(3).unwrap();
let marker_color = rh.field(marker_color_idx).unwrap().read()?;
assert_eq!(
marker_color,
dbase::FieldValue::Character(Some("#ff0000".to_string()))
);
let name = rh.field(name_idx).unwrap().read()?;
assert_eq!(
name,
dbase::FieldValue::Character(Some("Judiciary Sq".to_string()))
);
let marker_symbol = rh.field(marker_symbol_idx).unwrap().read()?;
assert_eq!(
marker_symbol,
dbase::FieldValue::Character(Some("rail-metro".to_string()))
);
Implementations§
source§impl<T> File<T>
impl<T> File<T>
sourcepub fn fields(&self) -> &[FieldInfo]
pub fn fields(&self) -> &[FieldInfo]
Returns the information about fields present in the records
sourcepub fn field_index(&self, name: &str) -> Option<FieldIndex>
pub fn field_index(&self, name: &str) -> Option<FieldIndex>
Returns the field index that corresponds to the given name
sourcepub fn num_records(&self) -> usize
pub fn num_records(&self) -> usize
Returns the number of records in the file
pub fn set_options(&mut self, options: ReadingOptions)
source§impl<T: Read + Seek> File<T>
impl<T: Read + Seek> File<T>
source§impl<T: Write + Seek> File<T>
impl<T: Write + Seek> File<T>
pub fn create_new(dst: T, table_info: TableInfo) -> Result<Self, Error>
pub fn append_record<R>(&mut self, record: &R) -> Result<(), Error>where
R: WritableRecord,
pub fn append_records<R>(&mut self, records: &[R]) -> Result<(), Error>where
R: WritableRecord,
pub fn sync_all(&mut self) -> Result<()>
source§impl File<BufReadWriteFile>
impl File<BufReadWriteFile>
pub fn open_with_options<P: AsRef<Path>>( path: P, options: OpenOptions ) -> Result<Self, Error>
sourcepub fn open_read_only<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub fn open_read_only<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Opens an existing dBase file in read only mode
sourcepub fn open_write_only<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub fn open_write_only<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Opens an existing dBase file in write only mode
Auto Trait Implementations§
impl<T> !RefUnwindSafe for File<T>
impl<T> Send for File<T>where
T: Send,
impl<T> !Sync for File<T>
impl<T> Unpin for File<T>where
T: Unpin,
impl<T> !UnwindSafe for File<T>
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