-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add more methods from the undocumented api
- Loading branch information
1 parent
eb950fa
commit 54847ce
Showing
5 changed files
with
361 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//! A set of macros for easily working with internals. | ||
//! | ||
//! ISC License (ISC) | ||
//! | ||
//! Copyright (c) 2016, Serenity Contributors | ||
//! | ||
//! Permission to use, copy, modify, and/or distribute this software for any purpose | ||
//! with or without fee is hereby granted, provided that the above copyright notice | ||
//! and this permission notice appear in all copies. | ||
//! | ||
//! THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
//! REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
//! FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
//! INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
//! OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
//! TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
//! THIS SOFTWARE. | ||
|
||
/// The macro forwards the generation to the `bitflags::bitflags!` macro and implements | ||
/// the default (de)serialization for Discord's bitmask values. | ||
/// | ||
/// The flags are created with `T::from_bits_truncate` for the deserialized integer value. | ||
/// | ||
/// Use the `bitflags::bitflags! macro directly if a different serde implementation is required. | ||
|
||
macro_rules! bitflags { | ||
( | ||
$(#[$outer:meta])* | ||
$vis:vis struct $BitFlags:ident: $T:ty { | ||
$( | ||
$(#[$inner:ident $($args:tt)*])* | ||
const $Flag:ident = $value:expr; | ||
)* | ||
} | ||
|
||
$($t:tt)* | ||
) => { | ||
bitflags::bitflags! { | ||
$(#[$outer])* | ||
$vis struct $BitFlags: $T { | ||
$( | ||
$(#[$inner $($args)*])* | ||
const $Flag = $value; | ||
)* | ||
} | ||
} | ||
|
||
bitflags!(__impl_serde $BitFlags: $T); | ||
|
||
bitflags! { | ||
$($t)* | ||
} | ||
}; | ||
(__impl_serde $BitFlags:ident: $T:tt) => { | ||
impl<'de> serde::de::Deserialize<'de> for $BitFlags { | ||
fn deserialize<D: serde::de::Deserializer<'de>>(deserializer: D) -> std::result::Result<Self, D::Error> { | ||
Ok(Self::from_bits_truncate(<$T>::deserialize(deserializer)?)) | ||
} | ||
} | ||
|
||
impl serde::ser::Serialize for $BitFlags { | ||
fn serialize<S: serde::ser::Serializer>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> { | ||
self.bits().serialize(serializer) | ||
} | ||
} | ||
}; | ||
() => {}; | ||
} | ||
|
||
pub(crate) use bitflags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.