pub struct ImageHash<B = Box<[u8]>> { /* private fields */ }Expand description
Re-export the ImageHash type from img_hash for convenience. A struct representing an image processed by a perceptual hash. For efficiency, does not retain a copy of the image data after hashing.
Get an instance with ImageHash::hash().
Implementations§
Source§impl<B> ImageHash<B>where
B: HashBytes,
impl<B> ImageHash<B>where
B: HashBytes,
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<ImageHash<B>, InvalidBytesError>
pub fn from_bytes(bytes: &[u8]) -> Result<ImageHash<B>, InvalidBytesError>
Create an ImageHash instance from the given bytes.
§Errors:
Returns a InvalidBytesError::BytesWrongLength error if the slice passed can’t fit in B.
Sourcepub fn dist(&self, other: &ImageHash<B>) -> u32
pub fn dist(&self, other: &ImageHash<B>) -> u32
Calculate the Hamming distance between this and other.
Equivalent to counting the 1-bits of the XOR of the two hashes.
Essential to determining the perceived difference between self and other.
§Note
This return value is meaningless if these two hashes are from different hash sizes or algorithms.
Sourcepub fn from_base64(
encoded_hash: &str,
) -> Result<ImageHash<B>, InvalidBytesError>
pub fn from_base64( encoded_hash: &str, ) -> Result<ImageHash<B>, InvalidBytesError>
Create an ImageHash instance from the given Base64-encoded string.
§Errors:
Returns InvaidBytesError::Base64(DecodeError::InvalidLength) if the string wasn’t valid base64. Otherwise returns the same errors as from_bytes`.
Trait Implementations§
impl<B> Eq for ImageHash<B>where
B: Eq,
impl<B> StructuralPartialEq for ImageHash<B>
Auto Trait Implementations§
impl<B> Freeze for ImageHash<B>where
B: Freeze,
impl<B> RefUnwindSafe for ImageHash<B>where
B: RefUnwindSafe,
impl<B> Send for ImageHash<B>where
B: Send,
impl<B> Sync for ImageHash<B>where
B: Sync,
impl<B> Unpin for ImageHash<B>where
B: Unpin,
impl<B> UnsafeUnpin for ImageHash<B>where
B: UnsafeUnpin,
impl<B> UnwindSafe for ImageHash<B>where
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more