Re: [PATCH 05/14] rust: add a hash algorithm abstraction
On Tue, Oct 28, 2025 at 2:00 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 22 quoted lines
>
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
> > +#[allow(dead_code)]
> > +impl ObjectID {
> > + pub fn as_slice(&self) -> &[u8] {
> > + match HashAlgorithm::from_u32(self.algo) {
> > + Some(algo) => &self.hash[0..algo.raw_len()],
> > + None => &self.hash,
> > + }
> > + }
> > +
> > + pub fn as_mut_slice(&mut self) -> &mut [u8] {
> > + match HashAlgorithm::from_u32(self.algo) {
> > + Some(algo) => &mut self.hash[0..algo.raw_len()],
> > + None => &mut self.hash,
> > + }
> > + }
> > +}
>
> These cases for "None" surprised me a bit; I would have expected us
> to error out when given an algorithm we do not recognise.I think _Result_ would be more appropriate here.