Skip to content

Commit

Permalink
Change imports to vertical
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronKutch committed Dec 7, 2019
1 parent 4a31e0a commit 8d810c1
Show file tree
Hide file tree
Showing 24 changed files with 284 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ hard_tabs = false
hide_parse_errors = false
ignore = []
imports_indent = "Block"
imports_layout = "HorizontalVertical" # handles lots of imports better
imports_layout = "Vertical" # makes editing quicker
indent_style = "Block"
inline_attribute_width = 0 # unchanged, for ease of editing
# license_template_path = "LICENSE_TEMPLATE" # changed
Expand Down Expand Up @@ -71,4 +71,4 @@ use_small_heuristics = "Default"
use_try_shorthand = true # changed
version = "Two" # changed
where_single_line = false # unchanged, for ease of editing
wrap_comments = true # fits comments to the line
wrap_comments = true # fits comments to the line
41 changes: 34 additions & 7 deletions src/apint/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,42 @@ use crate::{
utils::{
DataAccessMut,
ZipDataAccessMutBoth,
ZipDataAccessMutSelf::{Ext, Inl},
ZipDataAccessMutSelf::{
Ext,
Inl,
},
},
ApInt,
},
digit,
digit::{Digit, DoubleDigit},
errors::{DivOp, Error, Result},
mem::{vec, vec::Vec},
digit::{
Digit,
DoubleDigit,
},
errors::{
DivOp,
Error,
Result,
},
mem::{
vec,
vec::Vec,
},
traits::Width,
utils::{forward_mut_impl, try_forward_bin_mut_impl},
utils::{
forward_mut_impl,
try_forward_bin_mut_impl,
},
};
use core::ops::{
Add,
AddAssign,
Mul,
MulAssign,
Neg,
Sub,
SubAssign,
};
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};

// Moved here because of a bug in rustfmt. This entire file will be broken up in
// a future commit. assigns `$sum + $sub` to `$target`,
Expand Down Expand Up @@ -1915,7 +1939,10 @@ mod tests {
mod mul {
use super::*;
use crate::bitwidth::BitWidth;
use core::{u64, u8};
use core::{
u64,
u8,
};

#[test]
fn rigorous() {
Expand Down
20 changes: 17 additions & 3 deletions src/apint/bitwise.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{
apint::{
utils::{DataAccess, DataAccessMut},
utils::{
DataAccess,
DataAccessMut,
},
ApInt,
},
bitpos::BitPos,
Expand All @@ -9,10 +12,21 @@ use crate::{
digit::Bit,
errors::Result,
traits::Width,
utils::{forward_mut_impl, try_forward_bin_mut_impl},
utils::{
forward_mut_impl,
try_forward_bin_mut_impl,
},
};

use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};
use core::ops::{
BitAnd,
BitAndAssign,
BitOr,
BitOrAssign,
BitXor,
BitXorAssign,
Not,
};

/// # Bitwise Operations
impl ApInt {
Expand Down
15 changes: 12 additions & 3 deletions src/apint/casting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ use crate::{
apint::ApInt,
bitwidth::BitWidth,
digit::Bit,
errors::{Error, Result},
errors::{
Error,
Result,
},
mem::format,
storage::Storage,
traits::Width,
utils::{forward_bin_mut_impl, try_forward_bin_mut_impl},
utils::{
forward_bin_mut_impl,
try_forward_bin_mut_impl,
},
};

impl Clone for ApInt {
Expand Down Expand Up @@ -732,7 +738,10 @@ mod tests {

#[test]
fn regression_issue15() {
use core::{i128, i64};
use core::{
i128,
i64,
};
{
let input = ApInt::from_i64(i64::MIN)
.into_sign_extend(BitWidth::new(128).unwrap())
Expand Down
25 changes: 20 additions & 5 deletions src/apint/constructors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use crate::{
apint::{ApInt, ApIntData},
apint::{
ApInt,
ApIntData,
},
bitwidth::BitWidth,
digit,
digit::{Bit, Digit},
errors::{Error, Result},
digit::{
Bit,
Digit,
},
errors::{
Error,
Result,
},
mem::vec::Vec,
storage::Storage,
};
Expand Down Expand Up @@ -422,7 +431,10 @@ mod tests {
}

mod tests {
use super::{powers, powers_from_to};
use super::{
powers,
powers_from_to,
};

#[test]
fn test_powers() {
Expand Down Expand Up @@ -616,7 +628,10 @@ mod tests {

#[test]
fn from_w128() {
use crate::digit::{Digit, DigitRepr};
use crate::digit::{
Digit,
DigitRepr,
};
for val in test_values_u128() {
let explicit_u128 = ApInt::from_u128(val);
let explicit_i128 = ApInt::from_i128(val as i128);
Expand Down
5 changes: 4 additions & 1 deletion src/apint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ mod rand_impl;
#[cfg(feature = "serde_support")]
mod serde_impl;

use crate::{bitwidth::BitWidth, digit::Digit};
use crate::{
bitwidth::BitWidth,
digit::Digit,
};

pub use self::shift::ShiftAmount;
pub(crate) use self::to_primitive::PrimitiveTy;
Expand Down
16 changes: 13 additions & 3 deletions src/apint/rand_impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{apint::ApInt, bitwidth::BitWidth, digit::Digit};
use crate::{
apint::ApInt,
bitwidth::BitWidth,
digit::Digit,
};
use rand::SeedableRng as _;

impl rand::distributions::Distribution<Digit> for rand::distributions::Standard {
Expand Down Expand Up @@ -28,7 +32,10 @@ impl ApInt {
{
let required_digits = width.required_digits();
assert!(required_digits >= 1);
use rand::distributions::{Distribution, Standard};
use rand::distributions::{
Distribution,
Standard,
};
let random_digits = Standard.sample_iter(rng).take(required_digits);
// The truncation will be cheap always!
ApInt::from_iter(random_digits)
Expand Down Expand Up @@ -58,7 +65,10 @@ impl ApInt {
where
R: rand::Rng,
{
use rand::distributions::{Distribution, Standard};
use rand::distributions::{
Distribution,
Standard,
};
let std_dist = Standard.sample_iter(rng);
self.digits_mut().zip(std_dist).for_each(|(d, r)| *d = r);
self.clear_unused_bits();
Expand Down
10 changes: 8 additions & 2 deletions src/apint/relational.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use crate::{
apint::{utils::ZipDataAccess, ApInt},
apint::{
utils::ZipDataAccess,
ApInt,
},
digit,
digit::Bit,
errors::Result,
mem::format,
traits::Width,
};
use core::{cmp::Ordering, ops::Not};
use core::{
cmp::Ordering,
ops::Not,
};

/// If `self` and `other` have unmatching bit widths, `false` will be returned.
impl PartialEq for ApInt {
Expand Down
28 changes: 23 additions & 5 deletions src/apint/serde_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use crate::{apint::ApInt, bitwidth::BitWidth, digit::Digit};
use crate::{
apint::ApInt,
bitwidth::BitWidth,
digit::Digit,
};

use serde::{ser::SerializeTupleStruct, Serialize, Serializer};
use serde::{
ser::SerializeTupleStruct,
Serialize,
Serializer,
};

impl Serialize for Digit {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -31,7 +39,10 @@ impl Serialize for ApInt {
where
S: Serializer,
{
use serde::ser::{SerializeStruct, SerializeTuple};
use serde::ser::{
SerializeStruct,
SerializeTuple,
};

if serializer.is_human_readable() {
let mut s = serializer.serialize_struct("ApInt", 2)?;
Expand All @@ -50,7 +61,11 @@ impl Serialize for ApInt {
use core::fmt;
use serde::{
de,
de::{MapAccess, SeqAccess, Visitor},
de::{
MapAccess,
SeqAccess,
Visitor,
},
Deserialize,
Deserializer,
};
Expand Down Expand Up @@ -296,7 +311,10 @@ impl<'de> Deserialize<'de> for ApInt {
mod tests {
use super::*;

use serde_test::{assert_tokens, Token};
use serde_test::{
assert_tokens,
Token,
};

mod compact {
use super::*;
Expand Down
25 changes: 20 additions & 5 deletions src/apint/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use crate::{
apint::ApInt,
digit,
errors::{Error, Result},
mem::{string::String, vec::Vec},
errors::{
Error,
Result,
},
mem::{
string::String,
vec::Vec,
},
radix::Radix,
};
use core::fmt;
Expand Down Expand Up @@ -190,7 +196,10 @@ impl ApInt {
//
// TODO: Better document what happens here and why.
fn from_bitwise_digits(v: &[u8], bits: usize) -> ApInt {
use crate::digit::{Digit, DigitRepr};
use crate::digit::{
Digit,
DigitRepr,
};

debug_assert!(!v.is_empty() && bits <= 8 && digit::BITS % bits == 0);
debug_assert!(v.iter().all(|&c| DigitRepr::from(c) < (1 << bits)));
Expand All @@ -217,7 +226,10 @@ impl ApInt {
//
// TODO: Better document what happens here and why.
fn from_inexact_bitwise_digits(v: &[u8], bits: usize) -> ApInt {
use crate::digit::{Digit, DigitRepr};
use crate::digit::{
Digit,
DigitRepr,
};

debug_assert!(!v.is_empty() && bits <= 8 && digit::BITS % bits != 0);
debug_assert!(v.iter().all(|&c| (DigitRepr::from(c)) < (1 << bits)));
Expand Down Expand Up @@ -259,7 +271,10 @@ impl ApInt {
// TODO: This does not work, yet. Some parts of the algorithm are
// commented-out since the required functionality does not exist, yet.
fn from_radix_digits(v: &[u8], radix: Radix) -> ApInt {
use crate::digit::{Digit, DigitRepr};
use crate::digit::{
Digit,
DigitRepr,
};
#[cfg(feature = "libm_0")]
use libm::F64Ext as _;

Expand Down
10 changes: 8 additions & 2 deletions src/apint/shift.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use crate::{
apint::{utils::DataAccessMut, ApInt},
apint::{
utils::DataAccessMut,
ApInt,
},
checks,
digit,
digit::{Bit, Digit},
digit::{
Bit,
Digit,
},
errors::Result,
traits::Width,
utils::try_forward_bin_mut_impl,
Expand Down
5 changes: 4 additions & 1 deletion src/apint/to_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use crate::{
bitwidth::BitWidth,
digit,
digit::Digit,
errors::{Error, Result},
errors::{
Error,
Result,
},
traits::Width,
};

Expand Down
Loading

0 comments on commit 8d810c1

Please sign in to comment.