noodles_fasta/
fai.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! FASTA index (FAI) and fields.

#[cfg(feature = "async")]
pub mod r#async;

mod index;
pub mod io;
mod record;

pub use self::{index::Index, record::Record};

#[deprecated(since = "0.44.0", note = "Use `fai::io::Reader` instead.")]
pub use self::io::Reader;

#[deprecated(since = "0.44.0", note = "Use `fai::io::Writer` instead.")]
pub use self::io::Writer;

#[cfg(feature = "async")]
#[deprecated(since = "0.44.0", note = "Use `fai::r#async::io::Reader` instead.")]
pub use self::r#async::io::Reader as AsyncReader;

use std::{fs::File, io::BufReader, path::Path};

/// Reads the entire contents of a FASTA index.
///
/// This is a convenience function and is equivalent to opening the file at the given path and
/// parsing each record.
///
/// # Examples
///
/// ```no_run
/// # use std::io;
/// use noodles_fasta::fai;
/// let index = fai::read("reference.fa.fai")?;
/// # Ok::<(), io::Error>(())
/// ```
pub fn read<P>(src: P) -> std::io::Result<Index>
where
    P: AsRef<Path>,
{
    let mut reader = File::open(src).map(BufReader::new).map(Reader::new)?;
    reader.read_index()
}