Skip to content

Commit

Permalink
cargo +nightly fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Feb 22, 2024
1 parent 2fe0737 commit 39063c9
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 60 deletions.
2 changes: 1 addition & 1 deletion benches/possum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Spotted in github.com/rnbguy/rope

reorder_imports = true

# unstable features
group_imports = "StdExternalCrate"
imports_granularity = "Module"
5 changes: 3 additions & 2 deletions src/c_api/types.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/c_api/types/value.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/cpathbuf.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/dir.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ impl From<windows::core::Error> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
50 changes: 24 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -33,20 +12,39 @@ 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;
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;
Expand Down
6 changes: 2 additions & 4 deletions src/sys/clonefile/sys.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![allow(unused_imports)]
use super::*;

use std::ffi::CString;
#[cfg(target_os = "linux")]
use std::fs::File;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/flock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ pub fn try_lock_file(file: &mut File, arg: FlockArg) -> anyhow::Result<bool> {

#[cfg(test)]
mod tests {
use tempfile::NamedTempFile;

use super::*;
use crate::test;
use tempfile::NamedTempFile;

#[test]
fn open_locked_file() -> anyhow::Result<()> {
Expand Down
3 changes: 2 additions & 1 deletion src/sys/flock/unix.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/sys/flock/windows.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/sys/punchfile/linux.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/sys/punchfile/macos.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/sys/punchfile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion src/sys/punchfile/windows.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/sys/seekhole/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
3 changes: 2 additions & 1 deletion src/sys/windows.rs
Original file line number Diff line number Diff line change
@@ -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<FILE_ALLOCATED_RANGE_BUFFER>;

pub fn query_allocated_ranges(
Expand Down
3 changes: 1 addition & 2 deletions src/testing.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/walk.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fs::DirEntry as StdDirEntry;
use std::fs::FileType;
use std::fs::{DirEntry as StdDirEntry, FileType};

use super::*;

Expand Down
6 changes: 2 additions & 4 deletions tests/simple_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 39063c9

Please sign in to comment.