Struct dbase::File

source ·
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>

source

pub fn fields(&self) -> &[FieldInfo]

Returns the information about fields present in the records

source

pub fn field_index(&self, name: &str) -> Option<FieldIndex>

Returns the field index that corresponds to the given name

source

pub fn num_records(&self) -> usize

Returns the number of records in the file

source

pub fn set_options(&mut self, options: ReadingOptions)

source§

impl<T: Read + Seek> File<T>

source

pub fn open(source: T) -> Result<Self, Error>

creates of File using source as the storage space.

source

pub fn record(&mut self, index: usize) -> Option<RecordRef<'_, T>>

Returns a reference to the record at the given index.

Returns None if no record exist for the given index

source

pub fn records(&mut self) -> FileRecordIterator<'_, T>

Returns an iterator over the records in the file.

Always starts at the first record

source§

impl<T: Write + Seek> File<T>

source

pub fn create_new(dst: T, table_info: TableInfo) -> Result<Self, Error>

source

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

source

pub fn append_records<R>(&mut self, records: &[R]) -> Result<(), Error>
where R: WritableRecord,

source

pub fn sync_all(&mut self) -> Result<()>

source§

impl File<BufReadWriteFile>

source

pub fn open_with_options<P: AsRef<Path>>( path: P, options: OpenOptions ) -> Result<Self, Error>

source

pub fn open_read_only<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Opens an existing dBase file in read only mode

source

pub fn open_write_only<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Opens an existing dBase file in write only mode

source

pub fn open_read_write<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Opens an existing dBase file in read and write mode

source

pub fn create<P: AsRef<Path>>( path: P, table_info: TableInfo ) -> Result<Self, Error>

This function will create a file if it does not exist, and will truncate it if it does.

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