diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-19 22:28:49 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-19 22:39:19 +0100 |
| commit | ab43bd802eafe33977a91893907e67553e099569 (patch) | |
| tree | af4dead92b143348f52e2e8f869df3f7dfd7322a /src/util/mod.rs | |
| parent | d6aaae0cea1e79eecd85dc94ab85b9ad8eff48e8 (diff) | |
Renaming and refactoring
Diffstat (limited to 'src/util/mod.rs')
| -rw-r--r-- | src/util/mod.rs | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/util/mod.rs b/src/util/mod.rs index 596282de..3e0e7aa2 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -40,7 +40,7 @@ pub fn hash128<T: Hash + ?Sized>(value: &T) -> u128 { state.finish128().as_u128() } -/// Extra methods for [`NonZeroUsize`]. +/// An extra constant for [`NonZeroUsize`]. pub trait NonZeroExt { /// The number `1`. const ONE: Self; @@ -210,7 +210,13 @@ pub fn pretty_array_like(parts: &[impl AsRef<str>], trailing_comma: bool) -> Str buf.push('('); if list.contains('\n') { buf.push('\n'); - buf.push_str(&indent(&list, 2)); + for (i, line) in list.lines().enumerate() { + if i > 0 { + buf.push('\n'); + } + buf.push_str(" "); + buf.push_str(line); + } buf.push('\n'); } else { buf.push_str(&list); @@ -218,18 +224,3 @@ pub fn pretty_array_like(parts: &[impl AsRef<str>], trailing_comma: bool) -> Str buf.push(')'); buf } - -/// Indent a string by two spaces. -pub fn indent(text: &str, amount: usize) -> String { - let mut buf = String::new(); - for (i, line) in text.lines().enumerate() { - if i > 0 { - buf.push('\n'); - } - for _ in 0..amount { - buf.push(' '); - } - buf.push_str(line); - } - buf -} |
