Skip to content

Commit

Permalink
Don't allocate when encoding commit hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
w4 committed Jan 8, 2025
1 parent 6a76f81 commit 73690ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ external-default-features = "allow"
allow = []
deny = []
skip = [
{ crate = "[email protected]", reason = "tower has not upgraded to 1.0 yet" },
{ crate = "[email protected]", reason = "gix pulls in two separate versions" },
]
skip-tree = [
Expand Down
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
./statics
./templates
./themes
./deny.toml
./build.rs
];
};
Expand Down Expand Up @@ -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";
Expand Down
15 changes: 13 additions & 2 deletions src/methods/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::{
borrow::Borrow,
fmt::Display,
sync::{Arc, LazyLock},
};

Expand Down Expand Up @@ -40,8 +41,18 @@ pub fn file_perms(s: &u16) -> Result<String, askama::Error> {
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> {
Expand Down

0 comments on commit 73690ab

Please sign in to comment.