summaryrefslogtreecommitdiffstats
path: root/openpgp/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-10-20 15:24:49 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-10-20 16:09:59 +0200
commit5110c70a33ef6e6e5814d845f8ede167cd00dcc7 (patch)
treeef6736b7b4dfb335b8db87936d86a82e980d67ea /openpgp/src
parentb0b91ae1d569e67306ab64305e5c444de4b1bf00 (diff)
openpgp: Fix indentation.
- Correctly handle negative indentation levels.
Diffstat (limited to 'openpgp/src')
-rw-r--r--openpgp/src/macros.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/openpgp/src/macros.rs b/openpgp/src/macros.rs
index 9b9e84e2..ba09c91c 100644
--- a/openpgp/src/macros.rs
+++ b/openpgp/src/macros.rs
@@ -33,9 +33,10 @@ macro_rules! trace {
}
// Converts an indentation level to whitespace.
-pub(crate) fn indent(i: usize) -> &'static str {
+pub(crate) fn indent(i: isize) -> &'static str {
+ use std::convert::TryFrom;
let s = " ";
- &s[0..cmp::min(i, s.len())]
+ &s[0..cmp::min(usize::try_from(i).unwrap_or(0), s.len())]
}
macro_rules! tracer {
@@ -48,29 +49,29 @@ macro_rules! tracer {
// https://users.rust-lang.org/t/nested-macros-issue/8348/2
macro_rules! t {
( $fmt:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, $fmt) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, $fmt) };
( $fmt:expr, $a:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a)) };
( $fmt:expr, $a:expr, $b:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr, $e:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d, $e)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d, $e)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d, $e, $f)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d, $e, $f)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr, $g:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr, $g:expr, $h:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr, $g:expr, $h:expr, $i:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h, $i)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h, $i)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr, $g:expr, $h:expr, $i:expr, $j:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h, $i, $j)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h, $i, $j)) };
( $fmt:expr, $a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr, $g:expr, $h:expr, $i:expr, $j:expr, $k:expr ) =>
- { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent as usize), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k)) };
+ { trace!($TRACE, "{}{}: {}", crate::macros::indent($indent), $func, format!($fmt, $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k)) };
}
}
}