That's usually a chose unless we also re-export these crates. And that we just avoid for now as I have a feeling we can gain some speed by leveraging the lower-case garantuee offered by git. And even if not, we can be less abstract than what 'hex' does.
Showing the changes to git-object/src (1 of 2 files). Show all
Unified · Split
| @@ -1,7 +1,17 @@ | |||
| 1 | use crate::{borrowed, SHA1_SIZE}; | 1 | use crate::{borrowed, SHA1_SIZE}; |
| 2 | use bstr::ByteSlice; | 2 | use bstr::ByteSlice; |
| 3 | use quick_error::quick_error; | ||
| 3 | use std::{fmt, io, ops::Deref}; | 4 | use std::{fmt, io, ops::Deref}; |
| 4 | 5 | ||
| 6 | quick_error! { | ||
| 7 | #[derive(Debug)] | ||
| 8 | pub enum Error { | ||
| 9 | HexDecode(err: String) { | ||
| 10 | display("Failed to hex hash: {}", err) | ||
| 11 | } | ||
| 12 | } | ||
| 13 | } | ||
| 14 | |||
| 5 | /// An owned SHA1 identifying objects | 15 | /// An owned SHA1 identifying objects |
| 6 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] | 16 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] |
| 7 | #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] | 17 | #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] |
| @@ -30,9 +40,11 @@ impl Id { · 22 unmodified lines | |||
| 30 | 40 | ||
| 31 | /// Sha1 hash specific methods | 41 | /// Sha1 hash specific methods |
| 32 | impl Id { | 42 | impl Id { |
| 33 | pub fn from_40_bytes_in_hex(buf: &[u8]) -> Result<Id, hex::FromHexError> { | 43 | pub fn from_40_bytes_in_hex(buf: &[u8]) -> Result<Id, Error> { |
| 34 | use hex::FromHex; | 44 | use hex::FromHex; |
| 35 | Ok(Id(<[u8; 20]>::from_hex(buf)?)) | 45 | Ok(Id( |
| 46 | <[u8; 20]>::from_hex(buf).map_err(|err| Error::HexDecode(err.to_string()))? | ||
| 47 | )) | ||
| 36 | } | 48 | } |
| 37 | pub fn sha1(&self) -> &[u8; SHA1_SIZE] { | 49 | pub fn sha1(&self) -> &[u8; SHA1_SIZE] { |
| 38 | &self.0 | 50 | &self.0 |