pub struct ImageHash { /* private fields */ }Expand description
The hash of an image on Discord’s CDN — avatars, icons, banners, splashes and so on.
Discord sends image hashes as 32 hexadecimal characters, prefixed with a_ when the image
is animated (for example a_1269e74af4df7417b13759eae50c83dc). Instead of keeping that
34-byte string on the heap, ImageHash stores the decoded 16 bytes plus an animation flag:
it is 17 bytes, Copy, and Option<ImageHash> is also 17 bytes.
Formatting with Display reproduces the original string, which is what
CDN URLs need.
discord.js counterpart: none (a string in discord.js).
§Examples
use djs_model::util::ImageHash;
let hash: ImageHash = "a_1269e74af4df7417b13759eae50c83dc".parse().unwrap();
assert!(hash.is_animated());
assert_eq!(hash.to_string(), "a_1269e74af4df7417b13759eae50c83dc");Implementations§
Source§impl ImageHash
impl ImageHash
Sourcepub const fn new(bytes: [u8; 16], animated: bool) -> Self
pub const fn new(bytes: [u8; 16], animated: bool) -> Self
Creates an image hash from its raw 16 bytes.
discord.js counterpart: none (a string in discord.js).
Sourcepub const fn bytes(self) -> [u8; 16]
pub const fn bytes(self) -> [u8; 16]
Returns the raw 16 bytes of the hash.
discord.js counterpart: none (a string in discord.js).
Sourcepub const fn is_animated(self) -> bool
pub const fn is_animated(self) -> bool
Returns true if the image is animated (the hash had an a_ prefix).
Animated images are available as GIF (and WebP/AVIF animations) on the CDN.
discord.js counterpart: the a_ check User#avatarURL makes.
Sourcepub const fn parse(input: &str) -> Result<Self, ParseImageHashError>
pub const fn parse(input: &str) -> Result<Self, ParseImageHashError>
Parses an image hash such as a_1269e74af4df7417b13759eae50c83dc.
Both lowercase and uppercase hexadecimal digits are accepted.
discord.js counterpart: none (a string in discord.js).
§Errors
Returns ParseImageHashError if the input is not 32 hexadecimal characters with an
optional a_ prefix.
Trait Implementations§
impl Copy for ImageHash
Source§impl<'de> Deserialize<'de> for ImageHash
impl<'de> Deserialize<'de> for ImageHash
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for ImageHash
Formats the hash exactly as Discord sends it: lowercase hex with an a_ prefix if animated.
impl Display for ImageHash
Formats the hash exactly as Discord sends it: lowercase hex with an a_ prefix if animated.
impl Eq for ImageHash
impl StructuralPartialEq for ImageHash
Auto Trait Implementations§
impl Forget for ImageHash
impl Freeze for ImageHash
impl Move for ImageHash
impl RefUnwindSafe for ImageHash
impl Send for ImageHash
impl Sync for ImageHash
impl Unpin for ImageHash
impl UnsafeUnpin for ImageHash
impl UnwindSafe for ImageHash
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more