macros: Derive as_str()
for types that derive StringEnum
This commit is contained in:
parent
24b4dd69ad
commit
240c8bc4b8
@ -59,10 +59,3 @@ pub enum ThirdPartyIdRemovalStatus {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl ThirdPartyIdRemovalStatus {
|
||||
/// Creates a string slice from this `ThirdPartyIdRemovalStatus`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -212,13 +212,6 @@ pub enum RoomVersionStability {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl RoomVersionStability {
|
||||
/// Creates a string slice from this `RoomVersionStability`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about the `m.set_displayname` capability
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
@ -33,13 +33,6 @@ pub enum EventFormat {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl EventFormat {
|
||||
/// Creates a string slice from this `EventFormat`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EventFormat {
|
||||
fn default() -> Self {
|
||||
Self::Client
|
||||
@ -70,14 +63,6 @@ pub enum RelationType {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-msc3440")]
|
||||
impl RelationType {
|
||||
/// Creates a string slice from this `RelationType`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Filters to be applied to room events.
|
||||
#[derive(Clone, Debug, Default, Incoming, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
@ -135,11 +135,4 @@ pub mod v3 {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Method {
|
||||
/// Creates a string slice from this `Method`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,13 +100,6 @@ pub mod v3 {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl MembershipEventFilter {
|
||||
/// Creates a string slice from this `MembershipEventFilter`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "server"))]
|
||||
mod tests {
|
||||
use assert_matches::assert_matches;
|
||||
|
@ -189,13 +189,6 @@ pub enum RuleKind {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl RuleKind {
|
||||
/// Creates a string slice from this `RuleKind`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Which kind a pusher is.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
@ -211,10 +204,3 @@ pub enum PusherKind {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl PusherKind {
|
||||
/// Creates a string slice from this `PusherKind`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,6 @@ pub enum Visibility {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Visibility {
|
||||
/// Creates a string slice from this `Visibility`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Visibility {
|
||||
fn default() -> Self {
|
||||
Self::Private
|
||||
|
@ -203,11 +203,4 @@ pub mod v3 {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl RoomPreset {
|
||||
/// Creates a string slice from this `RoomPreset`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -265,13 +265,6 @@ pub mod v3 {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl GroupingKey {
|
||||
/// Creates a string slice from this `GroupingKey`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Requests that the server partitions the result set based on the provided list of keys.
|
||||
#[derive(Clone, Default, Debug, Incoming, Serialize)]
|
||||
#[incoming_derive(Default)]
|
||||
@ -315,13 +308,6 @@ pub mod v3 {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl SearchKeys {
|
||||
/// Creates a string slice from this `SearchKeys`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// The order in which to search for results.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
|
@ -13,10 +13,3 @@ pub enum TokenType {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl TokenType {
|
||||
/// Creates a string slice from this `TokenType`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -248,13 +248,6 @@ pub enum PublicRoomJoinRule {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl PublicRoomJoinRule {
|
||||
/// Returns the string name of this `PublicRoomJoinRule`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PublicRoomJoinRule {
|
||||
fn default() -> Self {
|
||||
Self::Public
|
||||
|
@ -126,11 +126,6 @@ pub enum Reason {
|
||||
}
|
||||
|
||||
impl Reason {
|
||||
/// Creates a string slice from this `Reason`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-msc2746")]
|
||||
fn serialize_option_with_default<S>(
|
||||
reason: &Option<Reason>,
|
||||
|
@ -33,13 +33,6 @@ pub enum HashAlgorithm {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl HashAlgorithm {
|
||||
/// Creates a string slice from this `HashAlgorithm`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// A key agreement protocol.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
@ -56,13 +49,6 @@ pub enum KeyAgreementProtocol {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl KeyAgreementProtocol {
|
||||
/// Creates a string slice from this `KeyAgreementProtocol`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// A message authentication code algorithm.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
@ -79,13 +65,6 @@ pub enum MessageAuthenticationCode {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl MessageAuthenticationCode {
|
||||
/// Creates a string slice from this `MessageAuthenticationCode`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// A Short Authentication String method.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
@ -102,13 +81,6 @@ pub enum ShortAuthenticationString {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl ShortAuthenticationString {
|
||||
/// Creates a string slice from this `ShortAuthenticationString`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// A relation which associates an `m.key.verification.request` with another key verification event.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
@ -150,13 +122,6 @@ pub enum VerificationMethod {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl VerificationMethod {
|
||||
/// Creates a string slice from this `VerificationMethod`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::{from_value as from_json_value, json};
|
||||
|
@ -127,13 +127,6 @@ pub enum CancelCode {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl CancelCode {
|
||||
/// Creates a string slice from this `CancelCode`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||
|
@ -44,10 +44,3 @@ pub enum Recommendation {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Recommendation {
|
||||
/// Creates a string slice from this `Recommendation`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -63,10 +63,3 @@ pub enum GuestAccess {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl GuestAccess {
|
||||
/// Creates a string slice from this `GuestAccess`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -79,10 +79,3 @@ pub enum HistoryVisibility {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl HistoryVisibility {
|
||||
/// Creates a string slice from this `HistoryVisibility`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -261,13 +261,6 @@ pub enum MembershipState {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl MembershipState {
|
||||
/// Creates a string slice from this `MembershipState`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about a third party invitation.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
@ -1484,13 +1484,6 @@ pub enum ServerNoticeType {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl ServerNoticeType {
|
||||
/// Creates a string slice from this `ServerNoticeType`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Types of usage limits.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
@ -1507,13 +1500,6 @@ pub enum LimitType {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl LimitType {
|
||||
/// Creates a string slice from this `LimitType`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// The format for the formatted representation of a message body.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
@ -1527,13 +1513,6 @@ pub enum MessageFormat {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl MessageFormat {
|
||||
/// Creates a string slice from this `MessageFormat`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Common message event content fields for message types that have separate plain-text and
|
||||
/// formatted representations.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
|
@ -47,10 +47,3 @@ pub enum FeedbackType {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl FeedbackType {
|
||||
/// Creates a string slice from this `FeedbackType`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -63,13 +63,6 @@ pub enum Action {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Action {
|
||||
/// Creates a string slice from this `Action`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about a requested key.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
|
@ -34,10 +34,3 @@ impl Default for &'_ PresenceState {
|
||||
&PresenceState::Online
|
||||
}
|
||||
}
|
||||
|
||||
impl PresenceState {
|
||||
/// Creates a string slice from this `PresenceState`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -463,13 +463,6 @@ pub enum PushFormat {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl PushFormat {
|
||||
/// Creates a string slice from this `PushFormat`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -17,10 +17,3 @@ pub enum ReceiptType {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl ReceiptType {
|
||||
/// Creates a string slice from this `ReceiptType`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,3 @@ pub enum RoomType {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl RoomType {
|
||||
/// Creates a string slice from this `RoomType`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
@ -234,13 +234,6 @@ pub enum Medium {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl Medium {
|
||||
/// Creates a string slice from this `Medium`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// An identifier external to Matrix.
|
||||
///
|
||||
/// To create an instance of this type, first create a `ThirdPartyIdentifierInit` and convert it to
|
||||
|
@ -98,11 +98,4 @@ pub mod v1 {
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl ProfileField {
|
||||
/// Creates a string slice from this `ProfileField`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,6 +328,7 @@ pub fn derive_string_enum(input: TokenStream) -> TokenStream {
|
||||
fn expand_all(input: ItemEnum) -> syn::Result<proc_macro2::TokenStream> {
|
||||
let as_ref_str_impl = expand_enum_as_ref_str(&input)?;
|
||||
let from_string_impl = expand_enum_from_string(&input)?;
|
||||
let as_str_impl = expand_as_str_as_ref_str(&input.ident)?;
|
||||
let display_impl = expand_display_as_ref_str(&input.ident)?;
|
||||
let serialize_impl = expand_serialize_as_ref_str(&input.ident)?;
|
||||
let deserialize_impl = expand_deserialize_from_cow_str(&input.ident)?;
|
||||
@ -335,6 +336,7 @@ pub fn derive_string_enum(input: TokenStream) -> TokenStream {
|
||||
Ok(quote! {
|
||||
#as_ref_str_impl
|
||||
#from_string_impl
|
||||
#as_str_impl
|
||||
#display_impl
|
||||
#serialize_impl
|
||||
#deserialize_impl
|
||||
|
@ -162,13 +162,6 @@ pub mod v1 {
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
impl NotificationPriority {
|
||||
/// Creates a string slice from this `NotificationPriority`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for NotificationPriority {
|
||||
fn default() -> Self {
|
||||
Self::High
|
||||
|
Loading…
x
Reference in New Issue
Block a user