History

[clone] Don't expose hex-error in public interfaces anymore

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.

Sebastian Thiel committed 6 years ago

Commit 92dab301 parent 4bc78422 files · +17 −7Browse files

Showing the changes to git-object/src (1 of 2 files). Show all

Unified · Split

git-object/src/owned/id.rs+14−2
@@ -1,7 +1,17 @@
1use crate::{borrowed, SHA1_SIZE};1use crate::{borrowed, SHA1_SIZE};
2use bstr::ByteSlice;2use bstr::ByteSlice;
3use quick_error::quick_error;
3use std::{fmt, io, ops::Deref};4use std::{fmt, io, ops::Deref};
4 5
6quick_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 objects15/// 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 methods41/// Sha1 hash specific methods
32impl Id {42impl 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.050 &self.0