🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2025-01-08 13:46:51.0 +07:00:00
committer Jordan Doyle <jordan@doyle.la> 2025-01-08 13:46:51.0 +07:00:00
commit
73690ab5f75eaa37e4d52bcf64b40b7d3a343c4a [patch]
tree
6076b93ffe1d61f6b1bbc78aee1cd90a2c8de737
parent
6a76f817ba52d7db0d420c31925048f4f7f237a9
download
73690ab5f75eaa37e4d52bcf64b40b7d3a343c4a.tar.gz

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(-)

diff --git a/deny.toml b/deny.toml
index 54336d3..b3e00dd 100644
--- a/deny.toml
+++ a/deny.toml
@@ -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 = [
diff --git a/flake.nix b/flake.nix
index bb80678..d9a8317 100644
--- a/flake.nix
+++ a/flake.nix
@@ -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";
diff --git a/src/methods/filters.rs b/src/methods/filters.rs
index 83a4bce..2724abe 100644
--- a/src/methods/filters.rs
+++ a/src/methods/filters.rs
@@ -1,8 +1,9 @@
// sorry clippy, we don't have a choice. askama forces this on us
#![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> {