Run cargo fmt

This commit is contained in:
sharkdp committed 2020-11-01 21:04:39 +01:00
1 parent 9432677d3a
commit afb249e854
2 files changed
+32 -22

No files matched your search

+27 -21
View File
@@ -131,12 +131,9 @@ fn run() -> Result<(), AnyhowError> {
let block_size = matches let block_size = matches
.value_of("block_size") .value_of("block_size")
.map(|bs| { .map(|bs| {
bs.parse::<i64>() bs.parse::<i64>().map_err(|e| anyhow!(e)).and_then(|x| {
.map_err(|e| anyhow!(e)) PositiveI64::new(x).ok_or_else(|| anyhow!("block size argument must be positive"))
.and_then(|x| { })
PositiveI64::new(x)
.ok_or_else(|| anyhow!("block size argument must be positive"))
})
}) })
.transpose()? .transpose()?
.unwrap_or_else(|| PositiveI64::new(512).unwrap()); .unwrap_or_else(|| PositiveI64::new(512).unwrap());
@@ -165,18 +162,18 @@ fn run() -> Result<(), AnyhowError> {
let parse_byte_count = |s| -> Result<u64, AnyhowError> { let parse_byte_count = |s| -> Result<u64, AnyhowError> {
Ok(parse_byte_offset(s, block_size)? Ok(parse_byte_offset(s, block_size)?
.assume_forward_offset_from_start()?.into()) .assume_forward_offset_from_start()?
.into())
}; };
let mut reader = if let Some(length) = matches let mut reader = if let Some(length) = matches
.value_of("length") .value_of("length")
.or_else(|| matches.value_of("bytes")) .or_else(|| matches.value_of("bytes"))
.map(|s| { .map(|s| {
parse_byte_count(s) parse_byte_count(s).context(anyhow!(
.context(anyhow!( "failed to parse `--length` arg {:?} as byte count",
"failed to parse `--length` arg {:?} as byte count", s
s ))
))
}) })
.transpose()? .transpose()?
{ {
@@ -310,11 +307,15 @@ struct ByteOffset {
} }
#[derive(Clone, Debug, ThisError)] #[derive(Clone, Debug, ThisError)]
#[error("negative offset specified, but only positive offsets (counts) are accepted in this context")] #[error(
"negative offset specified, but only positive offsets (counts) are accepted in this context"
)]
struct NegativeOffsetSpecifiedError; struct NegativeOffsetSpecifiedError;
impl ByteOffset { impl ByteOffset {
fn assume_forward_offset_from_start(&self) -> Result<NonNegativeI64, NegativeOffsetSpecifiedError> { fn assume_forward_offset_from_start(
&self,
) -> Result<NonNegativeI64, NegativeOffsetSpecifiedError> {
let &Self { value, kind } = self; let &Self { value, kind } = self;
match kind { match kind {
ByteOffsetKind::ForwardFromBeginning | ByteOffsetKind::ForwardFromLastOffset => { ByteOffsetKind::ForwardFromBeginning | ByteOffsetKind::ForwardFromLastOffset => {
@@ -362,7 +363,10 @@ fn parse_byte_offset(n: &str, block_size: PositiveI64) -> Result<ByteOffset, Byt
} }
}; };
match next_char { match next_char {
Some('+') => (check_empty_after_sign()?, ByteOffsetKind::ForwardFromLastOffset), Some('+') => (
check_empty_after_sign()?,
ByteOffsetKind::ForwardFromLastOffset,
),
Some('-') => (check_empty_after_sign()?, ByteOffsetKind::BackwardFromEnd), Some('-') => (check_empty_after_sign()?, ByteOffsetKind::BackwardFromEnd),
None => return Err(Empty), None => return Err(Empty),
_ => (n, ByteOffsetKind::ForwardFromBeginning), _ => (n, ByteOffsetKind::ForwardFromBeginning),
@@ -522,10 +526,12 @@ fn test_parse_byte_offset() {
// multiplication overflows u64 // multiplication overflows u64
error!("20000000TiB", UnitMultiplicationOverflow); error!("20000000TiB", UnitMultiplicationOverflow);
assert!(match parse_byte_offset("99999999999999999999", PositiveI64::new(512).unwrap()) { assert!(
// We can't check against the kind of the `ParseIntError`, so we'll just make sure it's the match parse_byte_offset("99999999999999999999", PositiveI64::new(512).unwrap()) {
// same as trying to do the parse directly. // We can't check against the kind of the `ParseIntError`, so we'll just make sure it's the
Err(ParseNum(e)) => e == "99999999999999999999".parse::<i64>().unwrap_err(), // same as trying to do the parse directly.
_ => false, Err(ParseNum(e)) => e == "99999999999999999999".parse::<i64>().unwrap_err(),
}); _ => false,
}
);
} }
+5 -1
View File
@@ -431,7 +431,11 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
if !self.header_was_printed() { if !self.header_was_printed() {
self.header(); self.header();
writeln!(self.writer, "│ │ No content to print │ │ │ │").ok(); writeln!(
self.writer,
"│ │ No content to print │ │ │ │"
)
.ok();
} }
self.footer(); self.footer();