Skip to content

Commit

Permalink
bgzf/gzi: Move reader to io module
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Jan 16, 2025
1 parent 4b784ea commit 0c20662
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 29 deletions.
6 changes: 6 additions & 0 deletions noodles-bgzf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@

* bgzf: Raise minimum supported Rust version (MSRV) to 1.73.0.

* bgzf/gzi: Move reader (`Reader`) to `io` module.

### Deprecated

* bgzf: Deprecate async re-exports (`AsyncReader` and `AsyncWriter`).

Use `bgzf::r#async::Reader` and `bgzf::r#async::Writer` instead.

* bgzf/gzi: Deprecate `Reader`.

Use `bgzf::gzi::io::Reader` instead.

* bgzf/gzi: Deprecate `AsyncReader` re-export.

Use `bgzf::gzi::r#async::Reader` instead.
Expand Down
15 changes: 7 additions & 8 deletions noodles-bgzf/src/gzi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
pub mod r#async;

mod index;
mod reader;
pub mod io;

pub use self::{index::Index, reader::Reader};
pub use self::index::Index;

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

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

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

/// Reads the entire contents of a GZ index.
///
Expand All @@ -35,7 +34,7 @@ use std::{
/// let index = gzi::read("in.gz.gzi")?;
/// # Ok::<_, io::Error>(())
/// ```
pub fn read<P>(src: P) -> io::Result<Index>
pub fn read<P>(src: P) -> std::io::Result<Index>
where
P: AsRef<Path>,
{
Expand Down
14 changes: 6 additions & 8 deletions noodles-bgzf/src/gzi/async.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
//! Async gzip index.
mod reader;

pub use self::reader::Reader;
pub mod io;

use std::path::Path;

use tokio::{
fs::File,
io::{self, BufReader},
};
use tokio::{fs::File, io::BufReader};

use super::Index;

#[deprecated(since = "0.35.0", note = "Use `gzi::r#async::io::Reader` instead.")]
pub use self::io::Reader;

/// Reads the entire contents of a GZ index.
///
/// This is a convenience function and is equivalent to opening the given path and reading the
Expand All @@ -30,7 +28,7 @@ use super::Index;
/// # Ok(())
/// # }
/// ```
pub async fn read<P>(src: P) -> io::Result<Index>
pub async fn read<P>(src: P) -> tokio::io::Result<Index>
where
P: AsRef<Path>,
{
Expand Down
5 changes: 5 additions & 0 deletions noodles-bgzf/src/gzi/async/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Async gzip index I/O.
mod reader;

pub use self::reader::Reader;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
/// ```
/// use noodles_bgzf::gzi;
/// let data = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
/// let reader = gzi::r#async::Reader::new(&data[..]);
/// let reader = gzi::r#async::io::Reader::new(&data[..]);
/// ```
pub fn new(inner: R) -> Self {
Self { inner }
Expand All @@ -34,16 +34,14 @@ where
/// # Examples
///
/// ```no_run
/// # use std::io;
/// #
/// # #[tokio::main]
/// # async fn main() -> io::Result<()> {
/// # async fn main() -> tokio::io::Result<()> {
/// use noodles_bgzf::gzi;
/// use tokio::fs::File;
///
/// let mut reader = File::open("in.gzi")
/// .await
/// .map(gzi::r#async::Reader::new)?;
/// .map(gzi::r#async::io::Reader::new)?;
///
/// let index = reader.read_index().await?;
/// # Ok(())
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions noodles-bgzf/src/gzi/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! gzip index I/O.
mod reader;

pub use self::reader::Reader;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod index;
use std::io::{self, Read};

use self::index::read_index;
use super::Index;
use crate::gzi::Index;

/// A gzip index (GZI) reader.
pub struct Reader<R> {
Expand All @@ -18,7 +18,7 @@ impl<R> Reader<R> {
/// ```
/// # use std::io;
/// use noodles_bgzf::gzi;
/// let reader = gzi::Reader::new(io::empty());
/// let reader = gzi::io::Reader::new(io::empty());
/// let _inner = reader.get_ref();
/// ```
pub fn get_ref(&self) -> &R {
Expand All @@ -32,7 +32,7 @@ impl<R> Reader<R> {
/// ```
/// # use std::io;
/// use noodles_bgzf::gzi;
/// let mut reader = gzi::Reader::new(io::empty());
/// let mut reader = gzi::io::Reader::new(io::empty());
/// let _inner = reader.get_mut();
/// ```
pub fn get_mut(&mut self) -> &mut R {
Expand All @@ -46,7 +46,7 @@ impl<R> Reader<R> {
/// ```
/// # use std::io;
/// use noodles_bgzf::gzi;
/// let reader = gzi::Reader::new(io::empty());
/// let reader = gzi::io::Reader::new(io::empty());
/// let _inner = reader.into_inner();
/// ```
pub fn into_inner(self) -> R {
Expand All @@ -65,7 +65,7 @@ where
/// ```
/// use noodles_bgzf::gzi;
/// let data = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
/// let reader = gzi::Reader::new(&data[..]);
/// let reader = gzi::io::Reader::new(&data[..]);
/// ```
pub fn new(inner: R) -> Self {
Self { inner }
Expand All @@ -78,11 +78,11 @@ where
/// # Examples
///
/// ```no_run
/// # use std::{fs::File, io};
/// # use std::fs::File;
/// use noodles_bgzf::gzi;
/// let mut reader = File::open("in.gzi").map(gzi::Reader::new)?;
/// let mut reader = File::open("in.gzi").map(gzi::io::Reader::new)?;
/// let index = reader.read_index()?;
/// # Ok::<(), io::Error>(())
/// # Ok::<(), std::io::Error>(())
/// ```
pub fn read_index(&mut self) -> io::Result<Index> {
read_index(&mut self.inner)
Expand Down
File renamed without changes.

0 comments on commit 0c20662

Please sign in to comment.