Add is_variant methods to all enums
This commit is contained in:
		
							parent
							
								
									1081273571
								
							
						
					
					
						commit
						6f5a2a5e90
					
				| 
						 | 
					@ -48,6 +48,7 @@ static_assertions = "1.1.0"
 | 
				
			||||||
percent-encoding = "2.2.0"
 | 
					percent-encoding = "2.2.0"
 | 
				
			||||||
thiserror = "1.0.38"
 | 
					thiserror = "1.0.38"
 | 
				
			||||||
derive_deref = "1.1.1"
 | 
					derive_deref = "1.1.1"
 | 
				
			||||||
 | 
					is_variant = "1.0.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies.parse_link_header]
 | 
					[dependencies.parse_link_header]
 | 
				
			||||||
version = "0.3.3"
 | 
					version = "0.3.3"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@ edition.workspace = true
 | 
				
			||||||
futures = "0.3.25"
 | 
					futures = "0.3.25"
 | 
				
			||||||
thiserror = "1"
 | 
					thiserror = "1"
 | 
				
			||||||
static_assertions = "1"
 | 
					static_assertions = "1"
 | 
				
			||||||
 | 
					is_variant = "1.0.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies.log]
 | 
					[dependencies.log]
 | 
				
			||||||
version = "0.4"
 | 
					version = "0.4"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
//! Module containing everything related to media attachements.
 | 
					//! Module containing everything related to media attachements.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::AttachmentId;
 | 
					use crate::AttachmentId;
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
use serde::{Deserialize, Serialize};
 | 
					use serde::{Deserialize, Serialize};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// A struct representing a media attachment.
 | 
					/// A struct representing a media attachment.
 | 
				
			||||||
| 
						 | 
					@ -62,7 +63,7 @@ pub struct ImageDetails {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// The type of media attachment.
 | 
					/// The type of media attachment.
 | 
				
			||||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
 | 
					#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq, IsVariant)]
 | 
				
			||||||
pub enum MediaType {
 | 
					pub enum MediaType {
 | 
				
			||||||
    /// An image.
 | 
					    /// An image.
 | 
				
			||||||
    #[serde(rename = "image")]
 | 
					    #[serde(rename = "image")]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,7 @@
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Error type
 | 
					/// Error type
 | 
				
			||||||
#[derive(Debug, thiserror::Error)]
 | 
					#[derive(Debug, thiserror::Error, IsVariant)]
 | 
				
			||||||
pub enum Error {
 | 
					pub enum Error {
 | 
				
			||||||
    #[error("unrecognized visibility '{invalid}'")]
 | 
					    #[error("unrecognized visibility '{invalid}'")]
 | 
				
			||||||
    VisibilityParsingError { invalid: String },
 | 
					    VisibilityParsingError { invalid: String },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,8 @@
 | 
				
			||||||
use crate::{notification::Notification, status::Status};
 | 
					use crate::{notification::Notification, status::Status};
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
use serde::{Deserialize, Serialize};
 | 
					use serde::{Deserialize, Serialize};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
 | 
					#[derive(Debug, Clone, Deserialize, Serialize, IsVariant)]
 | 
				
			||||||
/// Events that come from the /streaming/user API call
 | 
					/// Events that come from the /streaming/user API call
 | 
				
			||||||
pub enum Event {
 | 
					pub enum Event {
 | 
				
			||||||
    /// Update event
 | 
					    /// Update event
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
use serde::{de::Visitor, Deserialize, Deserializer, Serialize};
 | 
					use serde::{de::Visitor, Deserialize, Deserializer, Serialize};
 | 
				
			||||||
use time::{serde::iso8601, OffsetDateTime};
 | 
					use time::{serde::iso8601, OffsetDateTime};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,7 +55,7 @@ pub struct Filter {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Represents the various types of Filter contexts
 | 
					/// Represents the various types of Filter contexts
 | 
				
			||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
 | 
					#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, IsVariant)]
 | 
				
			||||||
#[serde(rename_all = "lowercase")]
 | 
					#[serde(rename_all = "lowercase")]
 | 
				
			||||||
pub enum FilterContext {
 | 
					pub enum FilterContext {
 | 
				
			||||||
    /// Represents the "home" context
 | 
					    /// Represents the "home" context
 | 
				
			||||||
| 
						 | 
					@ -73,7 +74,7 @@ pub enum FilterContext {
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
/// Please note that the spec requests that any unknown value be interpreted
 | 
					/// Please note that the spec requests that any unknown value be interpreted
 | 
				
			||||||
/// as "warn".
 | 
					/// as "warn".
 | 
				
			||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
 | 
					#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, IsVariant)]
 | 
				
			||||||
#[serde(rename_all = "lowercase")]
 | 
					#[serde(rename_all = "lowercase")]
 | 
				
			||||||
pub enum Action {
 | 
					pub enum Action {
 | 
				
			||||||
    /// Indicates filtered toots should show up, but with a warning
 | 
					    /// Indicates filtered toots should show up, but with a warning
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
use crate::NotificationId;
 | 
					use crate::NotificationId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::{account::Account, status::Status};
 | 
					use super::{account::Account, status::Status};
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
use serde::{Deserialize, Serialize};
 | 
					use serde::{Deserialize, Serialize};
 | 
				
			||||||
use time::{serde::iso8601, OffsetDateTime};
 | 
					use time::{serde::iso8601, OffsetDateTime};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +26,7 @@ pub struct Notification {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// The type of notification.
 | 
					/// The type of notification.
 | 
				
			||||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
 | 
					#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, IsVariant)]
 | 
				
			||||||
#[serde(rename_all = "lowercase")]
 | 
					#[serde(rename_all = "lowercase")]
 | 
				
			||||||
pub enum NotificationType {
 | 
					pub enum NotificationType {
 | 
				
			||||||
    /// Someone mentioned the application client in another status.
 | 
					    /// Someone mentioned the application client in another status.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,9 @@
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
use serde::Deserialize;
 | 
					use serde::Deserialize;
 | 
				
			||||||
use serde::Serialize;
 | 
					use serde::Serialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// The visibility of a status.
 | 
					/// The visibility of a status.
 | 
				
			||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
 | 
					#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq, IsVariant)]
 | 
				
			||||||
#[serde(rename_all = "lowercase")]
 | 
					#[serde(rename_all = "lowercase")]
 | 
				
			||||||
pub enum Visibility {
 | 
					pub enum Visibility {
 | 
				
			||||||
    /// A Direct message to a user
 | 
					    /// A Direct message to a user
 | 
				
			||||||
| 
						 | 
					@ -36,3 +37,17 @@ impl std::str::FromStr for Visibility {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[cfg(test)]
 | 
				
			||||||
 | 
					mod tests {
 | 
				
			||||||
 | 
					    use std::str::FromStr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[test]
 | 
				
			||||||
 | 
					    fn test_from_str() {
 | 
				
			||||||
 | 
					        assert!(Visibility::from_str("invalid")
 | 
				
			||||||
 | 
					            .expect_err("parsed invalid?")
 | 
				
			||||||
 | 
					            .is_visibility_parsing_error());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ use std::{error, fmt, io::Error as IoError, num::TryFromIntError};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(feature = "env")]
 | 
					#[cfg(feature = "env")]
 | 
				
			||||||
use envy::Error as EnvyError;
 | 
					use envy::Error as EnvyError;
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
use reqwest::{header::ToStrError as HeaderStrError, Error as HttpError, StatusCode};
 | 
					use reqwest::{header::ToStrError as HeaderStrError, Error as HttpError, StatusCode};
 | 
				
			||||||
use serde::Deserialize;
 | 
					use serde::Deserialize;
 | 
				
			||||||
use serde_json::Error as SerdeError;
 | 
					use serde_json::Error as SerdeError;
 | 
				
			||||||
| 
						 | 
					@ -17,7 +18,7 @@ use url::ParseError as UrlError;
 | 
				
			||||||
pub type Result<T> = ::std::result::Result<T, Error>;
 | 
					pub type Result<T> = ::std::result::Result<T, Error>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// enum of possible errors encountered using the mastodon API.
 | 
					/// enum of possible errors encountered using the mastodon API.
 | 
				
			||||||
#[derive(Debug, thiserror::Error)]
 | 
					#[derive(Debug, thiserror::Error, IsVariant)]
 | 
				
			||||||
pub enum Error {
 | 
					pub enum Error {
 | 
				
			||||||
    /// Error from the Mastodon API. This typically means something went
 | 
					    /// Error from the Mastodon API. This typically means something went
 | 
				
			||||||
    /// wrong with your authentication or data.
 | 
					    /// wrong with your authentication or data.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,7 @@ use std::{
 | 
				
			||||||
    str::FromStr,
 | 
					    str::FromStr,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use is_variant::IsVariant;
 | 
				
			||||||
use serde::ser::{Serialize, Serializer};
 | 
					use serde::ser::{Serialize, Serializer};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::errors::Error;
 | 
					use crate::errors::Error;
 | 
				
			||||||
| 
						 | 
					@ -257,19 +258,16 @@ impl fmt::Display for Scopes {
 | 
				
			||||||
/// Permission scope of the application.
 | 
					/// Permission scope of the application.
 | 
				
			||||||
/// [Details on what each permission provides][1]
 | 
					/// [Details on what each permission provides][1]
 | 
				
			||||||
/// [1]: https://github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md)
 | 
					/// [1]: https://github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md)
 | 
				
			||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
 | 
					#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, IsVariant)]
 | 
				
			||||||
enum Scope {
 | 
					#[serde(rename_all = "lowercase")]
 | 
				
			||||||
 | 
					pub enum Scope {
 | 
				
			||||||
    /// Read only permissions.
 | 
					    /// Read only permissions.
 | 
				
			||||||
    #[serde(rename = "read")]
 | 
					 | 
				
			||||||
    Read(Option<Read>),
 | 
					    Read(Option<Read>),
 | 
				
			||||||
    /// Write only permissions.
 | 
					    /// Write only permissions.
 | 
				
			||||||
    #[serde(rename = "write")]
 | 
					 | 
				
			||||||
    Write(Option<Write>),
 | 
					    Write(Option<Write>),
 | 
				
			||||||
    /// Only permission to add and remove followers.
 | 
					    /// Only permission to add and remove followers.
 | 
				
			||||||
    #[serde(rename = "follow")]
 | 
					 | 
				
			||||||
    Follow,
 | 
					    Follow,
 | 
				
			||||||
    /// Push permissions
 | 
					    /// Push permissions
 | 
				
			||||||
    #[serde(rename = "push")]
 | 
					 | 
				
			||||||
    Push,
 | 
					    Push,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -355,7 +353,7 @@ impl Default for Scope {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Represents the granular "read:___" oauth scopes
 | 
					/// Represents the granular "read:___" oauth scopes
 | 
				
			||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
 | 
					#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, IsVariant)]
 | 
				
			||||||
pub enum Read {
 | 
					pub enum Read {
 | 
				
			||||||
    /// Accounts
 | 
					    /// Accounts
 | 
				
			||||||
    #[serde(rename = "accounts")]
 | 
					    #[serde(rename = "accounts")]
 | 
				
			||||||
| 
						 | 
					@ -450,7 +448,7 @@ impl fmt::Display for Read {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Represents the granular "write:___" oauth scopes
 | 
					/// Represents the granular "write:___" oauth scopes
 | 
				
			||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
 | 
					#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, IsVariant)]
 | 
				
			||||||
pub enum Write {
 | 
					pub enum Write {
 | 
				
			||||||
    /// Accounts
 | 
					    /// Accounts
 | 
				
			||||||
    #[serde(rename = "accounts")]
 | 
					    #[serde(rename = "accounts")]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue