diff --git a/benches/possum.rs b/benches/possum.rs index 3e46e2b..fe93c72 100644 --- a/benches/possum.rs +++ b/benches/possum.rs @@ -284,9 +284,9 @@ fn multiple_benchmarks(c: &mut Criterion) { mod clonefile; mod torrent_storage; -use rusqlite::TransactionBehavior; use std::time::Duration; +use rusqlite::TransactionBehavior; use tempfile::tempdir; criterion_group!( name = benches; diff --git a/rustfmt.toml b/rustfmt.toml index bf96e77..ffddc39 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,7 @@ +# Spotted in github.com/rnbguy/rope + +reorder_imports = true + +# unstable features group_imports = "StdExternalCrate" +imports_granularity = "Module" diff --git a/src/c_api/types.rs b/src/c_api/types.rs index 8423ab3..afbf639 100644 --- a/src/c_api/types.rs +++ b/src/c_api/types.rs @@ -1,10 +1,11 @@ mod value; +use std::ffi::c_char; + +use libc::size_t; pub(crate) use value::*; use crate::{BatchWriter, ValueWriter}; -use libc::size_t; -use std::ffi::c_char; pub(crate) type PossumOffset = u64; diff --git a/src/c_api/types/value.rs b/src/c_api/types/value.rs index 0138cb9..254a56c 100644 --- a/src/c_api/types/value.rs +++ b/src/c_api/types/value.rs @@ -1,5 +1,4 @@ -use crate::*; -use crate::{SnapshotValue, Value}; +use crate::{SnapshotValue, Value, *}; // Opaque to the C interface. /// Represents a value obtained from a reader, before or after snapshot occurs. diff --git a/src/cpathbuf.rs b/src/cpathbuf.rs index 2cddc32..c92e310 100644 --- a/src/cpathbuf.rs +++ b/src/cpathbuf.rs @@ -1,10 +1,11 @@ #![allow(dead_code)] -use super::*; use std::convert::TryFrom; use std::ffi::{c_char, CString, NulError}; use std::path::Path; +use super::*; + /// A PathBuf like implementation for use with C APIs that expect a nul-terminated C string. Should /// convert easily from common Rust path types, and have methods that pass to C. pub(crate) struct CPathBuf(CString); diff --git a/src/dir.rs b/src/dir.rs index 3eb3935..1e43e50 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -1,7 +1,9 @@ -use super::*; -use pathconf::path_min_hole_size; use std::borrow::Borrow; +use pathconf::path_min_hole_size; + +use super::*; + #[derive(Clone, Debug)] pub(crate) struct Dir { path_buf: PathBuf, diff --git a/src/error.rs b/src/error.rs index 56a6154..f818a59 100644 --- a/src/error.rs +++ b/src/error.rs @@ -57,9 +57,10 @@ impl From for Error { #[cfg(test)] mod tests { - use crate::{Error, PubResult}; use anyhow::Context; + use crate::{Error, PubResult}; + #[test] fn test_downcast_double_contexted() { let res = Err::<(), _>(Error::UnsupportedFilesystem); diff --git a/src/handle.rs b/src/handle.rs index 3a9ad74..d87c21d 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -351,9 +351,9 @@ impl Handle { } } -use crate::dir::Dir; use item::Item; +use crate::dir::Dir; use crate::ownedtx::{OwnedReadTx, OwnedTxInner}; use crate::tx::{ReadOnlyRusqliteTransaction, ReadTransaction}; diff --git a/src/lib.rs b/src/lib.rs index 98efaf8..b4e4d43 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,26 +1,5 @@ #![allow(clippy::unused_unit)] -use crate::item::Item; -pub use crate::tx::Transaction; -use crate::tx::{PostCommitWork, ReadTransactionOwned}; -use crate::walk::walk_dir; -use crate::ValueLocation::{Nonzero, ZeroLength}; -use anyhow::Result; -use anyhow::{bail, Context}; -use cfg_if::cfg_if; -use chrono::NaiveDateTime; -pub use error::Error; -use exclusive_file::ExclusiveFile; -use file_id::{FileId, FileIdFancy}; -pub use handle::Handle; -use memmap2::Mmap; -use num::Integer; -use ownedtx::OwnedTx; -use positioned_io::ReadAt; -use rand::Rng; -use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef}; -use rusqlite::Error::QueryReturnedNoRows; -use rusqlite::{params, CachedStatement, Connection, Statement}; use std::borrow::Borrow; use std::cmp::min; use std::collections::{BTreeSet, HashMap, HashSet}; @@ -33,13 +12,26 @@ use std::num::TryFromIntError; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; use std::process::abort; -use std::str; use std::sync::{Arc, Mutex, MutexGuard, OnceLock}; use std::time::Duration; -use std::{fs, io}; -use sys::flock; -use sys::pathconf; -use sys::*; +use std::{fs, io, str}; + +use anyhow::{bail, Context, Result}; +use cfg_if::cfg_if; +use chrono::NaiveDateTime; +pub use error::Error; +use exclusive_file::ExclusiveFile; +use file_id::{FileId, FileIdFancy}; +pub use handle::Handle; +use memmap2::Mmap; +use num::Integer; +use ownedtx::OwnedTx; +use positioned_io::ReadAt; +use rand::Rng; +use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef}; +use rusqlite::Error::QueryReturnedNoRows; +use rusqlite::{params, CachedStatement, Connection, Statement}; +use sys::{flock, pathconf, *}; use tempfile::TempDir; #[cfg(test)] pub use test_log::test; @@ -47,6 +39,12 @@ use tracing::*; pub use walk::Entry as WalkEntry; use ErrorKind::InvalidInput; +use crate::item::Item; +pub use crate::tx::Transaction; +use crate::tx::{PostCommitWork, ReadTransactionOwned}; +use crate::walk::walk_dir; +use crate::ValueLocation::{Nonzero, ZeroLength}; + mod c_api; mod cpathbuf; mod error; diff --git a/src/sys/clonefile/sys.rs b/src/sys/clonefile/sys.rs index 3de9034..318bd21 100644 --- a/src/sys/clonefile/sys.rs +++ b/src/sys/clonefile/sys.rs @@ -1,6 +1,4 @@ #![allow(unused_imports)] -use super::*; - use std::ffi::CString; #[cfg(target_os = "linux")] use std::fs::File; @@ -10,9 +8,9 @@ use std::io::{Error, ErrorKind}; use std::os::unix::ffi::OsStrExt; use std::path::Path; -use libc::ENOTSUP; -use libc::EOPNOTSUPP; +use libc::{ENOTSUP, EOPNOTSUPP}; +use super::*; use crate::cpathbuf::CPathBuf; use crate::Error::UnsupportedFilesystem; use crate::PubResult; diff --git a/src/sys/flock/mod.rs b/src/sys/flock/mod.rs index c2ec261..bd922f2 100644 --- a/src/sys/flock/mod.rs +++ b/src/sys/flock/mod.rs @@ -23,9 +23,10 @@ pub fn try_lock_file(file: &mut File, arg: FlockArg) -> anyhow::Result { #[cfg(test)] mod tests { + use tempfile::NamedTempFile; + use super::*; use crate::test; - use tempfile::NamedTempFile; #[test] fn open_locked_file() -> anyhow::Result<()> { diff --git a/src/sys/flock/unix.rs b/src/sys/flock/unix.rs index e75d577..b41f44d 100644 --- a/src/sys/flock/unix.rs +++ b/src/sys/flock/unix.rs @@ -1,9 +1,10 @@ -use super::*; use std::io::SeekFrom; pub use nix::fcntl::FlockArg; pub use nix::fcntl::FlockArg::*; +use super::*; + fn seek_from_offset(seek_from: SeekFrom) -> i64 { use SeekFrom::*; match seek_from { diff --git a/src/sys/flock/windows.rs b/src/sys/flock/windows.rs index e01c4c0..cc0d1b1 100644 --- a/src/sys/flock/windows.rs +++ b/src/sys/flock/windows.rs @@ -1,10 +1,11 @@ -use super::*; use std::convert::TryInto; use std::fs::File; use std::io; use std::io::SeekFrom; use std::io::SeekFrom::Start; +use super::*; + #[derive(Debug)] pub enum FlockArg { LockShared, diff --git a/src/sys/mod.rs b/src/sys/mod.rs index ce0b766..1324807 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -6,13 +6,13 @@ pub mod pathconf; pub mod punchfile; pub mod seekhole; +use std::fs::File; + pub use clonefile::*; pub use flock::*; pub use punchfile::*; pub use seekhole::*; -use std::fs::File; - cfg_if! { if #[cfg(windows)] { mod windows; diff --git a/src/sys/punchfile/linux.rs b/src/sys/punchfile/linux.rs index 67613f9..54f55ae 100644 --- a/src/sys/punchfile/linux.rs +++ b/src/sys/punchfile/linux.rs @@ -1,8 +1,9 @@ -use super::*; use std::convert::TryInto; use std::io; use std::io::Error; +use super::*; + pub fn punchfile(file: &File, offset: u64, length: u64) -> io::Result<()> { // TODO: On solaris we want fcntl(F_FREESP); let fd = file.as_fd().as_raw_fd(); diff --git a/src/sys/punchfile/macos.rs b/src/sys/punchfile/macos.rs index 829ae05..35363e3 100644 --- a/src/sys/punchfile/macos.rs +++ b/src/sys/punchfile/macos.rs @@ -1,7 +1,8 @@ -use super::*; use std::io; use std::io::Error; +use super::*; + pub fn punchfile(file: &File, offset: u64, length: u64) -> io::Result<()> { // TODO: On solaris we want fcntl(F_FREESP); let punchhole = libc::fpunchhole_t { diff --git a/src/sys/punchfile/mod.rs b/src/sys/punchfile/mod.rs index d6de07c..619a3b3 100644 --- a/src/sys/punchfile/mod.rs +++ b/src/sys/punchfile/mod.rs @@ -17,10 +17,11 @@ use super::*; #[cfg(test)] mod tests { + use tempfile::NamedTempFile; + use self::test; use super::*; use crate::sys::pathconf::fd_min_hole_size; - use tempfile::NamedTempFile; #[test] #[allow(clippy::identity_op)] diff --git a/src/sys/punchfile/windows.rs b/src/sys/punchfile/windows.rs index aaf6235..b789fd2 100644 --- a/src/sys/punchfile/windows.rs +++ b/src/sys/punchfile/windows.rs @@ -1,7 +1,8 @@ -use super::*; use std::convert::TryInto; use std::io; +use super::*; + pub fn punchfile(file: &File, offset: u64, length: u64) -> io::Result<()> { let handle = std_handle_to_windows(file.as_raw_handle()); // FILE_ZERO_DATA_INFORMATION_EX exists but it's for drivers. diff --git a/src/sys/seekhole/unix.rs b/src/sys/seekhole/unix.rs index 7b9fc86..8e17545 100644 --- a/src/sys/seekhole/unix.rs +++ b/src/sys/seekhole/unix.rs @@ -6,8 +6,7 @@ use std::io; use std::io::Error; use std::os::fd::RawFd; -use libc::ENXIO; -use libc::{SEEK_DATA, SEEK_HOLE}; +use libc::{ENXIO, SEEK_DATA, SEEK_HOLE}; use super::*; diff --git a/src/sys/windows.rs b/src/sys/windows.rs index e8c5c27..67aa23e 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -1,9 +1,10 @@ //! Windows specific APIs -use super::*; use std::mem::{size_of, size_of_val}; use std::os::windows::fs::OpenOptionsExt; +use super::*; + type AllocatedRanges = Vec; pub fn query_allocated_ranges( diff --git a/src/testing.rs b/src/testing.rs index b7ac771..6e734b9 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -1,8 +1,7 @@ pub mod torrent_storage; use std::hash::Hasher; -use std::io::Write; -use std::io::{copy, SeekFrom}; +use std::io::{copy, SeekFrom, Write}; use anyhow::{ensure, Result}; use rand::Rng; diff --git a/src/walk.rs b/src/walk.rs index dfdbd72..7046687 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -1,5 +1,4 @@ -use std::fs::DirEntry as StdDirEntry; -use std::fs::FileType; +use std::fs::{DirEntry as StdDirEntry, FileType}; use super::*; diff --git a/tests/simple_tests.rs b/tests/simple_tests.rs index 798644a..04c9815 100644 --- a/tests/simple_tests.rs +++ b/tests/simple_tests.rs @@ -4,16 +4,14 @@ use std::error::Error; use std::fmt::{Debug, Display}; use std::fs::OpenOptions; use std::hash::Hasher; -use std::io::Read; use std::io::SeekFrom::Start; -use std::io::{Seek, Write}; +use std::io::{Read, Seek, Write}; use std::ops::Bound::Included; use std::ops::{RangeBounds, RangeInclusive}; use std::path::PathBuf; use std::str::FromStr; use std::thread::sleep; -use std::time::Duration; -use std::time::Instant; +use std::time::{Duration, Instant}; use anyhow::{anyhow, Context, Result}; use fdlimit::raise_fd_limit;