[−][src]Struct clgit::generic::Hash
Implementations
impl<T> Hash<T>
[src]
pub fn from_str(s: &str) -> Result<Self, HashParseError>
[src]
Construct a Hash from a hexidecimal string. The entire hash must be specified: 40 characters (SHA-1) or 64 (SHA-256)
Examples
use clgit::unknown::Hash; // aka clgit::generic::Hash<()> for good in [ // Legal SHA-1 hashes (20 bytes / 40 characters) "74da26a93c3eac22884a62bd8d70aab3434c9174", "89dd60cc88e4f89e0af91e2739c42a31c3a106bb", "eb6c43cb699caa2ccbc4e28f9ab75a2a17e4ee7c", // Uppercase is legal too "74DA26A93C3EAC22884A62BD8D70AAB3434C9174", "89DD60CC88E4F89E0AF91E2739C42A31C3A106BB", "EB6C43CB699CAA2CCBC4E28F9AB75A2A17E4EE7C", // SHA-256 hashes (40 bytes / 64 characters) "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", ].iter().cloned() { Hash::from_str(good).unwrap_or_else(|e| panic!("Failed to parse {}: {}", good, e)); } for bad in [ "eb6c43cb699caa2ccbc4e28f9ab75a2a17e4ee7c0", // too long "eb6c43cb699caa2ccbc4e28f9ab75a2a17e4ee7", // too short "eb6c43cb699caa2ccbc4e28f9ab75a2a17e4ee7!", // invalid character "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde", // too short "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0", // too long ].iter().cloned() { assert!(Hash::from_str(bad).is_err(), "Didn't expect to parse {}", bad); }
pub fn from_bytes(src: &[u8]) -> Result<Self, HashParseError>
[src]
Construct a Hash from a slice of bytes. The entire hash must be specified: 20 bytes (SHA-1) or 32 (SHA-256)
Examples
Hash::from_bytes(&[0u8; 20][..]).expect("20 bytes OK"); Hash::from_bytes(&[0u8; 32][..]).expect("32 bytes OK"); Hash::from_bytes(&[0u8; 19][..]).expect_err("19 bytes invalid"); Hash::from_bytes(&[0u8; 21][..]).expect_err("21 bytes invalid"); Hash::from_bytes(&[0u8; 31][..]).expect_err("31 bytes invalid"); Hash::from_bytes(&[0u8; 33][..]).expect_err("33 bytes invalid");
pub fn read_sha1(r: &mut impl Read) -> Result<Self>
[src]
Read 20 bytes from r
and treat it as a SHA-1 Hash
Example
let mut io = std::io::Cursor::new(vec![0; 128]); Hash::read_sha1(&mut io).unwrap();
pub fn read_sha256(r: &mut impl Read) -> Result<Self>
[src]
Read 32 bytes from r
and treat it as a SHA-256 Hash
Example
let mut io = std::io::Cursor::new(vec![0; 128]); Hash::read_sha256(&mut io).unwrap();
pub fn len(&self) -> usize
[src]
Get the number of bytes in this hash (20 or 32)
Example
assert!(hash.len() == 20 || hash.len() == 32);
pub fn bytes(&self) -> &[u8]
[src]
Get the bytes in this hash (length of 20 or 32)
Example
let bytes : &[u8] = hash.bytes(); assert!(bytes.len() == 20 || bytes.len() == 32);
pub fn first_byte(&self) -> u8
[src]
pub fn typeless(&self) -> Hash<()>
[src]
Discard type information for this hash
impl Hash<()>
[src]
Trait Implementations
impl<T> Clone for Hash<T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> Debug for Hash<T>
[src]
impl<T> Default for Hash<T>
[src]
impl<T> Display for Hash<T>
[src]
impl<T> Eq for Hash<T>
[src]
impl<T> FromStr for Hash<T>
[src]
fn from_str(s: &str) -> Result<Self, HashParseError>
[src]
type Err = HashParseError
The associated error which can be returned from parsing.
impl<T> Hash for Hash<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Ord for Hash<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Hash<()>> for Hash<Blob>
[src]
impl PartialEq<Hash<()>> for Hash<Commit>
[src]
impl PartialEq<Hash<()>> for Hash<Tree>
[src]
impl PartialEq<Hash<Blob>> for Hash<()>
[src]
impl PartialEq<Hash<Commit>> for Hash<()>
[src]
fn eq(&self, other: &Hash<Commit>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> PartialEq<Hash<T>> for Hash<T>
[src]
impl PartialEq<Hash<Tree>> for Hash<()>
[src]
impl<T> PartialOrd<Hash<T>> for Hash<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Hash<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Hash<T> where
T: Send,
T: Send,
impl<T> Sync for Hash<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Hash<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Hash<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,