From 3ab84b7ef0f46a45efadaddcbfd9631002d87820 Mon Sep 17 00:00:00 2001 From: Joey Beauvais-Feisthauer Date: Sat, 7 Dec 2024 03:59:00 -0500 Subject: [PATCH] Use `io::` prefix for IO structs and traits --- .../algebra/src/algebra/pair_algebra.rs | 19 +++---- .../algebra/src/algebra/steenrod_algebra.rs | 14 ++--- ext/crates/chart/src/lib.rs | 20 +++---- ext/crates/fp/build.rs | 4 +- ext/crates/fp/src/matrix/matrix_inner.rs | 13 ++--- ext/crates/fp/src/matrix/quasi_inverse.rs | 12 ++-- ext/crates/fp/src/matrix/subspace.rs | 9 +-- ext/crates/fp/src/vector/fp_wrapper/mod.rs | 11 ++-- ext/examples/bruner.rs | 8 +-- ext/src/nassau.rs | 17 +++--- ext/src/save.rs | 56 ++++++++++--------- ext/src/secondary.rs | 11 ++-- ext/src/utils.rs | 10 ++-- 13 files changed, 94 insertions(+), 110 deletions(-) diff --git a/ext/crates/algebra/src/algebra/pair_algebra.rs b/ext/crates/algebra/src/algebra/pair_algebra.rs index 17a8a9e5c..e9b80ccaa 100644 --- a/ext/crates/algebra/src/algebra/pair_algebra.rs +++ b/ext/crates/algebra/src/algebra/pair_algebra.rs @@ -17,7 +17,7 @@ use crate::{combinatorics, Algebra}; type HashMap = hashbrown::HashMap>; -use std::io::{Read, Write}; +use std::io; /// A lift of an algebra to a split pair algebra. See module introduction for more. pub trait PairAlgebra: Algebra { @@ -82,13 +82,12 @@ pub trait PairAlgebra: Algebra { /// indecomposable. fn p_tilde(&self) -> usize; - fn element_to_bytes(&self, elt: &Self::Element, buffer: &mut impl Write) - -> std::io::Result<()>; + fn element_to_bytes(&self, elt: &Self::Element, buffer: &mut impl io::Write) -> io::Result<()>; fn element_from_bytes( &self, degree: i32, - buffer: &mut impl Read, - ) -> std::io::Result; + buffer: &mut impl io::Read, + ) -> io::Result; } use std::cell::RefCell; @@ -299,11 +298,7 @@ impl PairAlgebra for MilnorAlgebra { } } - fn element_to_bytes( - &self, - elt: &Self::Element, - buffer: &mut impl Write, - ) -> std::io::Result<()> { + fn element_to_bytes(&self, elt: &Self::Element, buffer: &mut impl io::Write) -> io::Result<()> { elt.twos.to_bytes(buffer)?; for row in &elt.ys { for v in row { @@ -316,8 +311,8 @@ impl PairAlgebra for MilnorAlgebra { fn element_from_bytes( &self, degree: i32, - buffer: &mut impl Read, - ) -> std::io::Result { + buffer: &mut impl io::Read, + ) -> io::Result { let p = self.prime(); assert_eq!(p, TWO); diff --git a/ext/crates/algebra/src/algebra/steenrod_algebra.rs b/ext/crates/algebra/src/algebra/steenrod_algebra.rs index 5f0976572..f86d280a6 100644 --- a/ext/crates/algebra/src/algebra/steenrod_algebra.rs +++ b/ext/crates/algebra/src/algebra/steenrod_algebra.rs @@ -1,4 +1,4 @@ -use std::io::{Read, Write}; +use std::io; use anyhow::anyhow; use fp::{ @@ -263,16 +263,16 @@ impl crate::pair_algebra::PairAlgebra for AdemAlgebra { fn element_to_bytes( &self, _elt: &Self::Element, - _buffer: &mut impl Write, - ) -> std::io::Result<()> { + _buffer: &mut impl io::Write, + ) -> io::Result<()> { unimplemented!() } fn element_from_bytes( &self, _degree: i32, - _buffer: &mut impl Read, - ) -> std::io::Result { + _buffer: &mut impl io::Read, + ) -> io::Result { unimplemented!() } } @@ -286,8 +286,8 @@ impl crate::pair_algebra::PairAlgebra for SteenrodAlgebra { fn sigma_multiply_basis(&self, result: &mut Self::Element, coeff: u32, r_degree: i32, r_idx: usize, s_degree: i32, s_idx: usize); fn sigma_multiply(&self, result: &mut Self::Element, coeff: u32, r_degree: i32, r: FpSlice, s_degree: i32, s: FpSlice); fn a_multiply(&self, result: FpSliceMut, coeff: u32, r_degree: i32, r: FpSlice, s_degree: i32, s: &Self::Element); - fn element_to_bytes(&self, elt: &Self::Element, buffer: &mut impl Write) -> std::io::Result<()>; - fn element_from_bytes(&self, degree: i32, buffer: &mut impl Read) -> std::io::Result; + fn element_to_bytes(&self, elt: &Self::Element, buffer: &mut impl io::Write) -> io::Result<()>; + fn element_from_bytes(&self, degree: i32, buffer: &mut impl io::Read) -> io::Result; } fn element_is_zero(elt: &Self::Element) -> bool { diff --git a/ext/crates/chart/src/lib.rs b/ext/crates/chart/src/lib.rs index 48f2280d3..d2755ea03 100644 --- a/ext/crates/chart/src/lib.rs +++ b/ext/crates/chart/src/lib.rs @@ -1,6 +1,6 @@ #![deny(clippy::use_self)] -use std::{collections::HashMap, fmt::Display, io::Write}; +use std::{collections::HashMap, fmt::Display, io}; #[rustfmt::skip] const PATTERNS: [(f32, &[(f32, f32)]); 12] = [ @@ -105,14 +105,14 @@ pub trait Backend { } } -pub struct SvgBackend { +pub struct SvgBackend { out: T, max_x: i32, max_y: i32, num_nodes: HashMap<(i32, i32), usize>, } -impl SvgBackend { +impl SvgBackend { const GRID_WIDTH: i32 = 20; const MARGIN: i32 = 30; const STYLES: &'static str = r#" @@ -200,8 +200,8 @@ impl SvgBackend { } } -impl Backend for SvgBackend { - type Error = std::io::Error; +impl Backend for SvgBackend { + type Error = io::Error; const EXT: &'static str = "svg"; @@ -304,20 +304,20 @@ impl Backend for SvgBackend { } } -impl Drop for SvgBackend { +impl Drop for SvgBackend { fn drop(&mut self) { writeln!(self.out, "").unwrap(); } } -pub struct TikzBackend { +pub struct TikzBackend { out: T, max_x: i32, max_y: i32, num_nodes: HashMap<(i32, i32), usize>, } -impl TikzBackend { +impl TikzBackend { const HEADER: &'static str = r"\begin{tikzpicture}[ major-grid/.style={ opacity = 0.2 }, grid/.style={ opacity = 0.1 }, @@ -350,7 +350,7 @@ impl TikzBackend { } } -impl Backend for TikzBackend { +impl Backend for TikzBackend { type Error = std::io::Error; const EXT: &'static str = "tex"; @@ -432,7 +432,7 @@ impl Backend for TikzBackend { } } -impl Drop for TikzBackend { +impl Drop for TikzBackend { fn drop(&mut self) { writeln!(self.out, r#"\end{{tikzpicture}}"#).unwrap(); } diff --git a/ext/crates/fp/build.rs b/ext/crates/fp/build.rs index 780ccfc17..5ef3db2a7 100644 --- a/ext/crates/fp/build.rs +++ b/ext/crates/fp/build.rs @@ -1,10 +1,10 @@ -use std::io::Error; +use std::io; use build_const::ConstWriter; type Limb = u64; -fn main() -> Result<(), Error> { +fn main() -> io::Result<()> { // We want primes up to 2^8 - 1, because those will be the characteristics of the fields that // have degree at least 2 and order at most 2^16 - 1. We will use PRIME_TO_INDEX_MAP when // computing Zech logarithms. diff --git a/ext/crates/fp/src/matrix/matrix_inner.rs b/ext/crates/fp/src/matrix/matrix_inner.rs index c056baa11..0f0d9fb5f 100644 --- a/ext/crates/fp/src/matrix/matrix_inner.rs +++ b/ext/crates/fp/src/matrix/matrix_inner.rs @@ -1,6 +1,5 @@ use std::{ - fmt, - io::{Read, Write}, + fmt, io, ops::{Index, IndexMut}, }; @@ -83,8 +82,8 @@ impl Matrix { p: ValidPrime, rows: usize, columns: usize, - data: &mut impl Read, - ) -> std::io::Result { + data: &mut impl io::Read, + ) -> io::Result { let mut vectors: Vec = Vec::with_capacity(rows); for _ in 0..rows { vectors.push(FpVector::from_bytes(p, columns, data)?); @@ -97,7 +96,7 @@ impl Matrix { }) } - pub fn to_bytes(&self, data: &mut impl Write) -> std::io::Result<()> { + pub fn to_bytes(&self, data: &mut impl io::Write) -> io::Result<()> { for v in &self.vectors { v.to_bytes(data)?; } @@ -105,7 +104,7 @@ impl Matrix { } /// Read a vector of `isize` - pub(crate) fn write_pivot(v: &[isize], buffer: &mut impl Write) -> std::io::Result<()> { + pub(crate) fn write_pivot(v: &[isize], buffer: &mut impl io::Write) -> io::Result<()> { if cfg!(all(target_endian = "little", target_pointer_width = "64")) { unsafe { let buf: &[u8] = std::slice::from_raw_parts(v.as_ptr() as *const u8, v.len() * 8); @@ -121,7 +120,7 @@ impl Matrix { } /// Read a vector of `isize` of length `dim`. - pub(crate) fn read_pivot(dim: usize, data: &mut impl Read) -> std::io::Result> { + pub(crate) fn read_pivot(dim: usize, data: &mut impl io::Read) -> io::Result> { if cfg!(all(target_endian = "little", target_pointer_width = "64")) { let mut image = vec![0; dim]; unsafe { diff --git a/ext/crates/fp/src/matrix/quasi_inverse.rs b/ext/crates/fp/src/matrix/quasi_inverse.rs index ac062eca1..57827d5d6 100644 --- a/ext/crates/fp/src/matrix/quasi_inverse.rs +++ b/ext/crates/fp/src/matrix/quasi_inverse.rs @@ -1,4 +1,4 @@ -use std::io::{Read, Write}; +use std::io; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use itertools::Itertools; @@ -43,7 +43,7 @@ impl QuasiInverse { } } - pub fn to_bytes(&self, buffer: &mut impl Write) -> std::io::Result<()> { + pub fn to_bytes(&self, buffer: &mut impl io::Write) -> io::Result<()> { buffer.write_u64::(self.source_dimension() as u64)?; buffer.write_u64::(self.target_dimension() as u64)?; buffer.write_u64::(self.image_dimension() as u64)?; @@ -61,7 +61,7 @@ impl QuasiInverse { self.preimage.to_bytes(buffer) } - pub fn from_bytes(p: ValidPrime, data: &mut impl Read) -> std::io::Result { + pub fn from_bytes(p: ValidPrime, data: &mut impl io::Read) -> io::Result { let source_dim = data.read_u64::()? as usize; let target_dim = data.read_u64::()? as usize; let image_dim = data.read_u64::()? as usize; @@ -79,10 +79,10 @@ impl QuasiInverse { /// quasi-inverse row by row to minimize memory usage. pub fn stream_quasi_inverse( p: ValidPrime, - data: &mut impl Read, + data: &mut impl io::Read, results: &mut [T], inputs: &[S], - ) -> std::io::Result<()> + ) -> io::Result<()> where for<'a> &'a mut T: Into>, for<'a> &'a S: Into>, @@ -173,7 +173,7 @@ mod tests { let mut out0 = FpVector::new(p, 4); let mut out1 = FpVector::new(p, 4); - let mut cursor = std::io::Cursor::new(Vec::::new()); + let mut cursor = io::Cursor::new(Vec::::new()); qi.to_bytes(&mut cursor).unwrap(); cursor.set_position(0); diff --git a/ext/crates/fp/src/matrix/subspace.rs b/ext/crates/fp/src/matrix/subspace.rs index 173302b26..eda5a4337 100644 --- a/ext/crates/fp/src/matrix/subspace.rs +++ b/ext/crates/fp/src/matrix/subspace.rs @@ -1,7 +1,4 @@ -use std::{ - io::{Read, Write}, - ops::Deref, -}; +use std::{io, ops::Deref}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use itertools::Itertools; @@ -60,7 +57,7 @@ impl Subspace { ret } - pub fn from_bytes(p: ValidPrime, data: &mut impl Read) -> std::io::Result { + pub fn from_bytes(p: ValidPrime, data: &mut impl io::Read) -> io::Result { let rows = data.read_u64::()? as usize; let ambient_dimension = data.read_u64::()? as usize; @@ -71,7 +68,7 @@ impl Subspace { Ok(Self { matrix }) } - pub fn to_bytes(&self, buffer: &mut impl Write) -> std::io::Result<()> { + pub fn to_bytes(&self, buffer: &mut impl io::Write) -> io::Result<()> { buffer.write_u64::(self.matrix.rows() as u64)?; buffer.write_u64::(self.ambient_dimension() as u64)?; diff --git a/ext/crates/fp/src/vector/fp_wrapper/mod.rs b/ext/crates/fp/src/vector/fp_wrapper/mod.rs index 347ef4d98..922930f1e 100644 --- a/ext/crates/fp/src/vector/fp_wrapper/mod.rs +++ b/ext/crates/fp/src/vector/fp_wrapper/mod.rs @@ -12,10 +12,7 @@ //! we can't simply define `type FpVector = FqVector>` like we previously did: we need to use //! a transparent wrapper. -use std::{ - convert::TryInto, - io::{Read, Write}, -}; +use std::{convert::TryInto, io}; use itertools::Itertools; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -104,9 +101,9 @@ impl FpVector { pub fn new(p: P, len: usize) -> (from FqVector); pub fn new_with_capacity(p: P, len: usize, capacity: usize) -> (from FqVector); - pub fn update_from_bytes(&mut self, data: &mut impl Read) -> (std::io::Result<()>); - pub fn from_bytes(p: P, len: usize, data: &mut impl Read) -> (from io FqVector); - pub fn to_bytes(&self, buffer: &mut impl Write) -> (std::io::Result<()>); + pub fn update_from_bytes(&mut self, data: &mut impl io::Read) -> (io::Result<()>); + pub fn from_bytes(p: P, len: usize, data: &mut impl io::Read) -> (from io FqVector); + pub fn to_bytes(&self, buffer: &mut impl io::Write) -> (io::Result<()>); } pub fn from_slice(p: P, slice: &[u32]) -> Self { diff --git a/ext/examples/bruner.rs b/ext/examples/bruner.rs index 547a04e04..5c0c2e53a 100644 --- a/ext/examples/bruner.rs +++ b/ext/examples/bruner.rs @@ -19,7 +19,7 @@ use std::{ fs::File, - io::{BufRead, BufReader}, + io, path::{Path, PathBuf}, str::FromStr, sync::Arc, @@ -47,7 +47,7 @@ type FreeModuleHomomorphism = FMH; type FiniteChainComplex = FCC; /// Read the first non-empty line of `data` into `buf`. Returns whether a line is read -fn read_line(data: &mut impl BufRead, buf: &mut String) -> Result { +fn read_line(data: &mut impl io::BufRead, buf: &mut String) -> Result { buf.clear(); while buf.is_empty() { let num_bytes = data.read_line(buf)?; @@ -108,7 +108,7 @@ fn get_algebra_element<'a>( fn get_element( a: &MilnorAlgebra, m: &FreeModule, - input: &mut impl BufRead, + input: &mut impl io::BufRead, ) -> Result> { let mut buf = String::new(); if !read_line(input, &mut buf)? { @@ -188,7 +188,7 @@ fn read_bruner_resolution(data_dir: &Path, max_n: i32) -> Result<(u32, FiniteCha let m = cc.module(s); let d = cc.differential(s); - let mut f = BufReader::new( + let mut f = io::BufReader::new( File::open(data_dir.join(format!("hDiff.{s}"))) .with_context(|| format!("Failed to read hDiff.{s}"))?, ); diff --git a/ext/src/nassau.rs b/ext/src/nassau.rs index 3cd211841..84276e5a4 100644 --- a/ext/src/nassau.rs +++ b/ext/src/nassau.rs @@ -14,7 +14,7 @@ use std::{ fmt::Display, - io::{Read, Write}, + io, sync::{mpsc, Arc, Mutex}, }; @@ -195,7 +195,7 @@ impl MilnorSubalgebra { .unwrap_or(Self::zero_algebra()) } - fn to_bytes(&self, buffer: &mut impl Write) -> std::io::Result<()> { + fn to_bytes(&self, buffer: &mut impl io::Write) -> io::Result<()> { buffer.write_u64::(self.profile.len() as u64)?; buffer.write_all(&self.profile)?; @@ -205,7 +205,7 @@ impl MilnorSubalgebra { buffer.write_all(&zeros[0..padding]) } - fn from_bytes(data: &mut impl Read) -> std::io::Result { + fn from_bytes(data: &mut impl io::Read) -> io::Result { let len = data.read_u64::()? as usize; let mut profile = vec![0; len]; @@ -220,10 +220,7 @@ impl MilnorSubalgebra { Ok(Self { profile }) } - fn signature_to_bytes( - signature: &[PPartEntry], - buffer: &mut impl Write, - ) -> std::io::Result<()> { + fn signature_to_bytes(signature: &[PPartEntry], buffer: &mut impl io::Write) -> io::Result<()> { if cfg!(target_endian = "little") && std::mem::size_of::() == 2 { unsafe { let buf: &[u8] = std::slice::from_raw_parts( @@ -248,7 +245,7 @@ impl MilnorSubalgebra { Ok(()) } - fn signature_from_bytes(&self, data: &mut impl Read) -> std::io::Result> { + fn signature_from_bytes(&self, data: &mut impl io::Read) -> io::Result> { let len = self.profile.len(); let mut signature: Vec = vec![0; len]; @@ -481,13 +478,13 @@ impl> Resolution { #[tracing::instrument(skip_all, fields(signature = ?signature, throughput))] fn write_qi( - f: &mut Option, + f: &mut Option, scratch: &mut FpVector, signature: &[PPartEntry], next_mask: &[usize], full_matrix: &Matrix, masked_matrix: &AugmentedMatrix<2>, - ) -> std::io::Result<()> { + ) -> io::Result<()> { let f = match f { Some(f) => f, None => return Ok(()), diff --git a/ext/src/save.rs b/ext/src/save.rs index 34f14062c..9a016c303 100644 --- a/ext/src/save.rs +++ b/ext/src/save.rs @@ -1,7 +1,7 @@ use std::{ collections::HashSet, fs::File, - io::{BufRead, BufReader, BufWriter, Error, ErrorKind, Read, Write}, + io, path::{Path, PathBuf}, sync::{Arc, LazyLock, Mutex}, }; @@ -194,13 +194,13 @@ impl SaveKind { /// In addition to checking the checksum, we also keep track of which files are open, and we delete /// the open files if the program is terminated halfway. -pub struct ChecksumWriter { +pub struct ChecksumWriter { writer: T, path: PathBuf, adler: adler::Adler32, } -impl ChecksumWriter { +impl ChecksumWriter { pub fn new(path: PathBuf, writer: T) -> Self { Self { path, @@ -211,25 +211,25 @@ impl ChecksumWriter { } /// We only implement the functions required and the ones we actually use. -impl Write for ChecksumWriter { - fn write(&mut self, buf: &[u8]) -> std::io::Result { +impl io::Write for ChecksumWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { let bytes_written = self.writer.write(buf)?; self.adler.write_slice(&buf[0..bytes_written]); Ok(bytes_written) } - fn flush(&mut self) -> std::io::Result<()> { + fn flush(&mut self) -> io::Result<()> { self.writer.flush() } - fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> { + fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { self.writer.write_all(buf)?; self.adler.write_slice(buf); Ok(()) } } -impl std::ops::Drop for ChecksumWriter { +impl std::ops::Drop for ChecksumWriter { fn drop(&mut self) { if !std::thread::panicking() { // We may not have finished writing, so the data is wrong. It should not be given a @@ -247,12 +247,12 @@ impl std::ops::Drop for ChecksumWriter { } } -pub struct ChecksumReader { +pub struct ChecksumReader { reader: T, adler: adler::Adler32, } -impl ChecksumReader { +impl ChecksumReader { pub fn new(reader: T) -> Self { Self { reader, @@ -262,21 +262,21 @@ impl ChecksumReader { } /// We only implement the functions required and the ones we actually use. -impl Read for ChecksumReader { - fn read(&mut self, buf: &mut [u8]) -> std::io::Result { +impl io::Read for ChecksumReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { let bytes_read = self.reader.read(buf)?; self.adler.write_slice(&buf[0..bytes_read]); Ok(bytes_read) } - fn read_exact(&mut self, buf: &mut [u8]) -> std::io::Result<()> { + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { self.reader.read_exact(buf)?; self.adler.write_slice(buf); Ok(()) } } -impl std::ops::Drop for ChecksumReader { +impl std::ops::Drop for ChecksumReader { fn drop(&mut self) { if !std::thread::panicking() { // If we are panicking, we may not have read everything, and panic in panic @@ -295,11 +295,13 @@ impl std::ops::Drop for ChecksumReader { /// Open the file pointed to by `path` as a `Box`. If the file does not exist, look for /// compressed versions. -fn open_file(path: PathBuf) -> Option> { +fn open_file(path: PathBuf) -> Option> { + use io::BufRead; + // We should try in decreasing order of access speed. match File::open(&path) { Ok(f) => { - let mut reader = BufReader::new(f); + let mut reader = io::BufReader::new(f); if reader .fill_buf() .unwrap_or_else(|e| panic!("Error when reading from {path:?}: {e}")) @@ -313,7 +315,7 @@ fn open_file(path: PathBuf) -> Option> { return Some(Box::new(ChecksumReader::new(reader))); } Err(e) => { - if e.kind() != ErrorKind::NotFound { + if e.kind() != io::ErrorKind::NotFound { panic!("Error when opening {path:?}: {e}"); } } @@ -330,7 +332,7 @@ fn open_file(path: PathBuf) -> Option> { ))) } Err(e) => { - if e.kind() != ErrorKind::NotFound { + if e.kind() != io::ErrorKind::NotFound { panic!("Error when opening {path:?}"); } } @@ -348,7 +350,7 @@ pub struct SaveFile { } impl SaveFile { - fn write_header(&self, buffer: &mut impl Write) -> std::io::Result<()> { + fn write_header(&self, buffer: &mut impl io::Write) -> io::Result<()> { buffer.write_u32::(self.kind.magic())?; buffer.write_u32::(self.algebra.magic())?; buffer.write_u32::(self.b.s())?; @@ -359,13 +361,13 @@ impl SaveFile { }) } - fn validate_header(&self, buffer: &mut impl Read) -> std::io::Result<()> { + fn validate_header(&self, buffer: &mut impl io::Read) -> io::Result<()> { macro_rules! check_header { ($name:literal, $value:expr, $format:literal) => { let data = buffer.read_u32::()?; if data != $value { - return Err(Error::new( - ErrorKind::InvalidData, + return Err(io::Error::new( + io::ErrorKind::InvalidData, format!( "Invalid header: {} was {} but expected {}", $name, @@ -413,7 +415,7 @@ impl SaveFile { dir } - pub fn open_file(&self, dir: PathBuf) -> Option> { + pub fn open_file(&self, dir: PathBuf) -> Option> { let file_path = self.get_save_path(dir); let path_string = file_path.to_string_lossy().into_owned(); if let Some(mut f) = open_file(file_path) { @@ -442,18 +444,18 @@ impl SaveFile { false } - pub fn delete_file(&self, dir: PathBuf) -> std::io::Result<()> { + pub fn delete_file(&self, dir: PathBuf) -> io::Result<()> { let p = self.get_save_path(dir); match std::fs::remove_file(p) { Ok(()) => Ok(()), - Err(e) if e.kind() == ErrorKind::NotFound => Ok(()), + Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(()), Err(e) => Err(e), } } /// # Arguments /// - `overwrite`: Whether to overwrite a file if it already exists. - pub fn create_file(&self, dir: PathBuf, overwrite: bool) -> impl Write { + pub fn create_file(&self, dir: PathBuf, overwrite: bool) -> impl io::Write { let p = self.get_save_path(dir); tracing::info!("open_write: {}", p.to_string_lossy()); @@ -473,7 +475,7 @@ impl SaveFile { .open(&p) .with_context(|| format!("Failed to create save file {p:?}")) .unwrap(); - let mut f = ChecksumWriter::new(p, BufWriter::new(f)); + let mut f = ChecksumWriter::new(p, io::BufWriter::new(f)); self.write_header(&mut f).unwrap(); f } diff --git a/ext/src/secondary.rs b/ext/src/secondary.rs index 25f116859..e423487ca 100644 --- a/ext/src/secondary.rs +++ b/ext/src/secondary.rs @@ -1,7 +1,4 @@ -use std::{ - io::{Read, Write}, - sync::Arc, -}; +use std::{io, sync::Arc}; use algebra::{ module::{ @@ -74,7 +71,7 @@ impl SecondaryComposite { } } - pub fn to_bytes(&self, buffer: &mut impl Write) -> std::io::Result<()> { + pub fn to_bytes(&self, buffer: &mut impl io::Write) -> io::Result<()> { let algebra = self.target.algebra(); for composites in self.composite.iter() { buffer.write_u64::(composites.len() as u64)?; @@ -89,8 +86,8 @@ impl SecondaryComposite { target: Arc>, degree: i32, hit_generator: bool, - buffer: &mut impl Read, - ) -> std::io::Result { + buffer: &mut impl io::Read, + ) -> io::Result { let min_degree = target.min_degree(); let algebra = target.algebra(); let mut composite = BiVec::with_capacity(min_degree, degree); diff --git a/ext/src/utils.rs b/ext/src/utils.rs index 8001d6f5f..5a311d082 100644 --- a/ext/src/utils.rs +++ b/ext/src/utils.rs @@ -466,7 +466,7 @@ pub fn get_unit( } mod logging { - use std::io::Write; + use std::io; pub struct LogWriter { writer: T, @@ -474,14 +474,14 @@ mod logging { start: std::time::Instant, } - impl Write for LogWriter { - fn write(&mut self, buf: &[u8]) -> std::io::Result { + impl io::Write for LogWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { let written = self.writer.write(buf)?; self.bytes += written as u64; Ok(written) } - fn flush(&mut self) -> std::io::Result<()> { + fn flush(&mut self) -> io::Result<()> { self.writer.flush() } } @@ -504,7 +504,7 @@ mod logging { } } - impl LogWriter { + impl LogWriter { /// Return the throughput in MiB/s pub fn into_throughput(mut self) -> Throughput { self.writer.flush().unwrap();