pub struct SoundData { /* private fields */ }Expand description
A sound sent inside a JSON request body as a data URI (data:audio/mpeg;base64,…), like
ImageData for images (D-122).
Used by Create Guild Soundboard Sound.
The sound is kept as [Bytes] and base64-encoded while the body is serialized.
discord.js counterpart: the file option of GuildSoundboardSoundManager#create.
§Examples
use djs_model::util::SoundData;
// A (truncated) Ogg file: the media type is read from the file signature.
let sound = SoundData::new(&b"OggS\0\x02"[..]).unwrap();
assert_eq!(sound.content_type(), "audio/ogg");
assert_eq!(sound.to_string(), "data:audio/ogg;base64,T2dnUwAC");
assert!(SoundData::new(&b"\x89PNG\r\n\x1a\n"[..]).is_err());Implementations§
Source§impl SoundData
impl SoundData
Sourcepub fn new(data: impl Into<Bytes>) -> Result<Self, SoundDataError>
pub fn new(data: impl Into<Bytes>) -> Result<Self, SoundDataError>
A sound whose media type is detected from its file signature: MP3 (with an ID3 tag or starting with a frame) or Ogg.
discord.js counterpart: BufferResolvable and Base64Resolvable, as GuildSoundboardSoundCreateOptions#file takes them.
§Errors
SoundDataError when data is neither; use
with_content_type to send it anyway.
Sourcepub fn with_content_type(
data: impl Into<Bytes>,
content_type: impl Into<CompactString>,
) -> Self
pub fn with_content_type( data: impl Into<Bytes>, content_type: impl Into<CompactString>, ) -> Self
A sound of the given media type (e.g. audio/mpeg), which is not checked.
discord.js counterpart: BufferResolvable and Base64Resolvable, as GuildSoundboardSoundCreateOptions#file takes them.
Sourcepub const fn data(&self) -> &Bytes
pub const fn data(&self) -> &Bytes
The sound file’s contents.
discord.js counterpart: none (discord.js turns sounds into data URIs internally).
Sourcepub fn content_type(&self) -> &str
pub fn content_type(&self) -> &str
The sound’s media type (e.g. audio/ogg).
discord.js counterpart: none (discord.js detects the type internally).
Trait Implementations§
impl Eq for SoundData
impl StructuralPartialEq for SoundData
Auto Trait Implementations§
impl !Freeze for SoundData
impl RefUnwindSafe for SoundData
impl Send for SoundData
impl Sync for SoundData
impl Unpin for SoundData
impl UnsafeUnpin for SoundData
impl UnwindSafe for SoundData
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> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more