Don't allocate when encoding commit hashes
Diff
deny.toml | 1 -
flake.nix | 3 ++-
src/methods/filters.rs | 15 ++++++++++++++-
3 files changed, 15 insertions(+), 4 deletions(-)
@@ -35,7 +35,6 @@
allow = []
deny = []
skip = [
{ crate = "sync_wrapper@0.1.2", reason = "tower has not upgraded to 1.0 yet" },
{ crate = "windows-sys@0.52.0", reason = "gix pulls in two separate versions" },
]
skip-tree = [
@@ -48,6 +48,7 @@
./statics
./templates
./themes
./deny.toml
./build.rs
];
};
@@ -75,7 +76,7 @@
clippy = craneLib.cargoClippy buildArgs;
doc = craneLib.cargoDoc buildArgs;
audit = craneLib.cargoAudit { inherit advisory-db; src = cargoOnlySrc; };
deny = craneLib.cargoDeny { src = cargoOnlySrc; };
deny = craneLib.cargoDeny { inherit src; };
test = craneLib.cargoNextest (buildArgs // {
partitions = 1;
partitionType = "count";
@@ -1,8 +1,9 @@
#![allow(clippy::unnecessary_wraps, clippy::trivially_copy_pass_by_ref)]
use std::{
borrow::Borrow,
fmt::Display,
sync::{Arc, LazyLock},
};
@@ -40,8 +41,18 @@
Ok(unix_mode::to_string(u32::from(*s)))
}
pub fn hex(s: &[u8]) -> Result<String, askama::Error> {
Ok(const_hex::encode(s))
pub struct DisplayHexBuffer<const N: usize>(const_hex::Buffer<N>);
impl<const N: usize> Display for DisplayHexBuffer<N> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.0.as_str())
}
}
pub fn hex(s: &[u8; 20]) -> Result<DisplayHexBuffer<20>, askama::Error> {
let mut buf = const_hex::Buffer::new();
buf.format(s);
Ok(DisplayHexBuffer(buf))
}
pub fn gravatar(email: &str) -> Result<&'static str, askama::Error> {