noodles_fasta/
fs.rs

1//! FASTA filesystem operations.
2
3use std::{fs::File, io, path::Path};
4
5use super::{fai, io::Indexer};
6
7/// Indexes a FASTA file.
8///
9/// # Examples
10///
11/// ```no_run
12/// use noodles_fasta as fasta;
13/// let index = fasta::fs::index("reference.fa")?;
14/// # Ok::<(), std::io::Error>(())
15/// ```
16pub fn index<P>(src: P) -> io::Result<fai::Index>
17where
18    P: AsRef<Path>,
19{
20    let mut indexer = File::open(src).map(io::BufReader::new).map(Indexer::new)?;
21    let mut records = Vec::new();
22
23    while let Some(record) = indexer.index_record()? {
24        records.push(record);
25    }
26
27    Ok(fai::Index::from(records))
28}