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

A builder to configure and initialize a Decoder.

The fields to decode are opt-out: by default, the Decoder will extract all available fields found in the archive into each Record. Use the provided methods to avoid decoding uneeded fields.

For instance, to read a nucleotide archive and only extract sequences names, skipping decoding of sequences:

let decoder = nafcodec::DecoderBuilder::new()
    .sequence(false)
    .quality(false)
    .with_path("../data/phix.naf")
    .unwrap();
for record in decoder.map(Result::unwrap) {
    println!(">{}", record.id.unwrap());
}

Implementations§

source§

impl DecoderBuilder

source

pub fn new() -> Self

Create a new decoder builder with default parameters.

By default, all fields are extracted if they are available in the header.

source

pub fn from_flags<F: Into<Flags>>(flags: F) -> Self

Create a new decoder builder from the given flags.

This constructor can be used as a shortcut to setup decoding of a subset of supported fields. For instance, to read only the sequence identifiers and quality lines from an archive:

let mut decoder = DecoderBuilder::from_flags(Flag::Id | Flag::Quality)
    .with_path("../data/phix.naf")
    .unwrap();

let record = decoder.next().unwrap().unwrap();
assert!(record.sequence.is_none());
assert!(record.quality.is_some());
source

pub fn buffer_size(&mut self, buffer_size: usize) -> &mut Self

The buffer size to use while reading.

Note that Decoder uses a lot of buffered I/O, and that more than one buffer will be created. Nevertheless, a higher value will reduce the necessity to seek the reader while reading the different blocks.

By default, a buffer size of 4KiB is used for each internal buffer.

source

pub fn id(&mut self, id: bool) -> &mut Self

Whether or not to decode the sequence identifiers if available.

source

pub fn comment(&mut self, comment: bool) -> &mut Self

Whether or not to decode the sequence comment if available.

source

pub fn sequence(&mut self, sequence: bool) -> &mut Self

Whether or not to decode the sequence string if available.

source

pub fn quality(&mut self, quality: bool) -> &mut Self

Whether or not to decode the quality string if available.

source

pub fn mask(&mut self, mask: bool) -> &mut Self

Whether or not to perform region masking in the output sequence.

source

pub fn with_bytes<'data, 'z>( &self, bytes: &'data [u8] ) -> Result<Decoder<'z, BufReader<Cursor<&'data [u8]>>>, Error>

Consume the builder to get a decoder reading data from the given buffer.

source

pub fn with_path<'z, P: AsRef<Path>>( &self, path: P ) -> Result<Decoder<'z, BufReader<File>>, Error>

Consume the builder to get a decoder reading a file at the given path.

source

pub fn with_reader<'z, R: BufRead + Seek>( &self, reader: R ) -> Result<Decoder<'z, R>, Error>

Consume the builder to get a decoder reading data from reader.

Trait Implementations§

source§

impl Clone for DecoderBuilder

source§

fn clone(&self) -> DecoderBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DecoderBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for DecoderBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.