Skip to content

Commit

Permalink
Drop derive_more and thiserror, remove Copy from types that aren't en…
Browse files Browse the repository at this point in the history
…um (breaking change) (#85)
  • Loading branch information
ldesgoui authored Feb 17, 2020
1 parent 4503e9f commit eb2dcb7
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 102 deletions.
12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ features = ["discord_game_sdk_sys/doc"]
no-default-features = true

[dependencies]
bitflags = "1.2.1"
derive_more = "0.99.2"
bitflags = "1.2"
discord_game_sdk_sys = { path = "./sys", version = "1.0.0-rc.1" }
thiserror = "1.0"
log = "0.4"
memchr = "2.2.1"
scopeguard = "1.0.0"
image = { version = "0.23.0", default-features = false, optional = true }
memchr = "2.2"
scopeguard = "1.0"
image = { version = "0.23", default-features = false, optional = true }

[dev-dependencies]
pretty_env_logger = "0.4.0"
pretty_env_logger = "0.4"

[features]
default = ["link"]
Expand Down
4 changes: 2 additions & 2 deletions src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ use std::convert::TryInto;
/// );
/// # Ok(()) }
/// ```
#[derive(Clone, Copy, Eq, PartialEq, derive_more::From, derive_more::Into)]
#[derive(Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct Activity(pub(crate) sys::DiscordActivity);

impl Activity {
/// Create a new Activity with empty fields
pub fn empty() -> Self {
Self::from(sys::DiscordActivity::default())
Self(sys::DiscordActivity::default())
}

/// Check if an Activity is completely blank
Expand Down
2 changes: 1 addition & 1 deletion src/entitlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{sys, EntitlementKind, Snowflake};
/// This must then be consumed by your game's backend
///
/// > [Struct in official docs](https://discordapp.com/developers/docs/game-sdk/store#data-models-entitlement-struct)
#[derive(Clone, Copy, Eq, Hash, PartialEq, derive_more::From, derive_more::Into)]
#[derive(Clone, Eq, Hash, PartialEq)]
#[repr(transparent)]
pub struct Entitlement(pub(crate) sys::DiscordEntitlement);

Expand Down
104 changes: 59 additions & 45 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::sys;
use std::fmt;

/// Alias for a `Result` with the error type [`discord_game_sdk::Error`]
///
Expand All @@ -8,181 +9,194 @@ pub type Result<T> = std::result::Result<T, Error>;
/// Discord Error
///
/// > [Enum in official docs](https://discordapp.com/developers/docs/game-sdk/discord#data-models-result-enum)
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, thiserror::Error)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Error {
/// Discord isn't working
#[error("service unavailable")]
ServiceUnavailable,

/// The SDK version is outdated
#[error("invalid version")]
InvalidVersion,

/// An internal erorr on transactional operations
#[error("lock failed")]
LockFailed,

/// Internal error
#[error("internal error")]
Internal,

/// Invalid payload
#[error("invalid payload")]
InvalidPayload,

/// Invalid command
#[error("invalid command")]
InvalidCommand,

/// Invalid permissions
#[error("invalid permissions")]
InvalidPermissions,

/// Could not fetch
#[error("not fetched")]
NotFetched,

/// Not found
#[error("not found")]
NotFound,

/// User already has network connection open on that channel
#[error("conflict")]
Conflict,

/// Activity secrets must be unique and not match party id
#[error("invalid secret")]
InvalidSecret,

/// Join request for that user does not exist
#[error("invalid join secret")]
InvalidJoinSecret,

/// Invalid Application ID in Activity payload (none should be set)
#[error("no eligible activity")]
NoEligibleActivity,

/// Invalid invite
#[error("invalid invite")]
InvalidInvite,

/// Not authenticated
#[error("not authenticated")]
NotAuthenticated,

/// The user's bearer token is invalid
#[error("invalid access token")]
InvalidAccessToken,

/// Access token belongs to another application
#[error("application mismatch")]
ApplicationMismatch,

/// Internal error fetching image data
#[error("invalid data URL")]
InvalidDataUrl,

/// Invalid base64 data
#[error("invalid base-64")]
InvalidBase64,

/// Trying to access data before it was filtered
#[error("not filtered")]
NotFiltered,

/// Lobby full
#[error("lobby full")]
LobbyFull,

/// Invalid lobby secret
#[error("invalid lobby secret")]
InvalidLobbySecret,

/// Filename is too long
#[error("invalid filename")]
InvalidFilename,

/// File is too big
#[error("invalid file size")]
InvalidFileSize,

/// Invalid entitlement
#[error("invalid entitlement")]
InvalidEntitlement,

/// Discord is not installed
#[error("not installed")]
NotInstalled,

/// Discord is not running
#[error("not running")]
NotRunning,

/// Insufficient buffer
#[error("insufficient buffer")]
InsufficientBuffer,

/// Purchase canceled
#[error("purchase canceled")]
PurchaseCanceled,

/// Invalid guild
#[error("invalid guild")]
InvalidGuild,

/// Invalid event
#[error("invalid event")]
InvalidEvent,

/// Invalid channel
#[error("invalid channel")]
InvalidChannel,

/// Invalid origin
#[error("invalid origin")]
InvalidOrigin,

/// Rate limited
#[error("rate limited")]
RateLimited,

/// `OAuth2` error
#[error("OAuth 2.0 error")]
OAuth2,

/// Select channel timeout
#[error("select channel timeout")]
SelectChannelTimeout,

/// Get guild timeout
#[error("get guild timeout")]
GetGuildTimeout,

/// Select voice force required
#[error("select voice force required")]
SelectVoiceForceRequired,

/// Capture shortcut already listening
#[error("capture shortcut already listening")]
CaptureShortcutAlreadyListening,

/// Unauthorized for achievement
#[error("unauthorized for achievement")]
UnauthorizedForAchievement,

/// Invalid gift code
#[error("invalid gift code")]
InvalidGiftCode,

/// Purchase error
#[error("purchase error")]
Purchase,

/// Transaction aborted
#[error("transaction aborted")]
TransactionAborted,

/// Safety net for missing definitions
#[error("undefined error {0}")]
Undefined(sys::EDiscordResult),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Error::*;

let message = match self {
ServiceUnavailable => "service unavailable",
InvalidVersion => "invalid version",
LockFailed => "lock failed",
Internal => "internal error",
InvalidPayload => "invalid payload",
InvalidCommand => "invalid command",
InvalidPermissions => "invalid permissions",
NotFetched => "not fetched",
NotFound => "not found",
Conflict => "conflict",
InvalidSecret => "invalid secret",
InvalidJoinSecret => "invalid join secret",
NoEligibleActivity => "no eligible activity",
InvalidInvite => "invalid invite",
NotAuthenticated => "not authenticated",
InvalidAccessToken => "invalid access token",
ApplicationMismatch => "application mismatch",
InvalidDataUrl => "invalid data URL",
InvalidBase64 => "invalid base-64",
NotFiltered => "not filtered",
LobbyFull => "lobby full",
InvalidLobbySecret => "invalid lobby secret",
InvalidFilename => "invalid filename",
InvalidFileSize => "invalid file size",
InvalidEntitlement => "invalid entitlement",
NotInstalled => "not installed",
NotRunning => "not running",
InsufficientBuffer => "insufficient buffer",
PurchaseCanceled => "purchase canceled",
InvalidGuild => "invalid guild",
InvalidEvent => "invalid event",
InvalidChannel => "invalid channel",
InvalidOrigin => "invalid origin",
RateLimited => "rate limited",
OAuth2 => "OAuth 2.0 error",
SelectChannelTimeout => "select channel timeout",
GetGuildTimeout => "get guild timeout",
SelectVoiceForceRequired => "select voice force required",
CaptureShortcutAlreadyListening => "capture shortcut already listening",
UnauthorizedForAchievement => "unauthorized for achievement",
InvalidGiftCode => "invalid gift code",
Purchase => "purchase error",
TransactionAborted => "transaction aborted",
Undefined(n) => return write!(f, "undefined error {}", n),
};

write!(f, "{}", message)
}
}

impl std::error::Error for Error {}
2 changes: 1 addition & 1 deletion src/file_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::convert::TryInto;
/// File Metadata
///
/// > [Struct in official docs](https://discordapp.com/developers/docs/game-sdk/storage#data-models-filestat-struct)
#[derive(Clone, Copy, Eq, PartialEq, derive_more::From, derive_more::Into)]
#[derive(Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct FileStat(pub(crate) sys::DiscordFileStat);

Expand Down
2 changes: 1 addition & 1 deletion src/image_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{sys, ImageKind, Snowflake, UserID};
/// Image Handle
///
/// > [Enum in official docs](https://discordapp.com/developers/docs/game-sdk/images#data-models-imagehandle-struct)
#[derive(Clone, Copy, Eq, Hash, PartialEq, derive_more::From, derive_more::Into)]
#[derive(Clone, Eq, Hash, PartialEq)]
#[repr(transparent)]
pub struct ImageHandle(pub(crate) sys::DiscordImageHandle);

Expand Down
2 changes: 1 addition & 1 deletion src/input_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
///
/// > [Struct in official docs](https://discordapp.com/developers/docs/game-sdk/discord-voice#data-models-inputmode-struct)
/// > [Shortcut keys in official docs](https://discordapp.com/developers/docs/game-sdk/discord-voice#data-models-shortcut-keys)
#[derive(Clone, Copy, Eq, PartialEq, derive_more::From, derive_more::Into)]
#[derive(Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct InputMode(pub(crate) sys::DiscordInputMode);

Expand Down
2 changes: 1 addition & 1 deletion src/lobby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{sys, utils::charbuf_to_str, LobbyID, LobbyKind, UserID};
/// Lobby
///
/// > [Struct in official docs](https://discordapp.com/developers/docs/game-sdk/lobbies#data-models-lobby-struct)
#[derive(Clone, Copy, Eq, PartialEq, derive_more::From, derive_more::Into)]
#[derive(Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct Lobby(pub(crate) sys::DiscordLobby);

Expand Down
2 changes: 1 addition & 1 deletion src/lobby_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::sys;
/// Lobby Type
///
/// > [Method in official docs](https://discordapp.com/developers/docs/game-sdk/lobbies#data-models-lobbytype-enum)
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum LobbyKind {
/// Lobby is public
Public,
Expand Down
3 changes: 1 addition & 2 deletions src/methods/activities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ impl Discord {
///
/// ```rust
/// # use discord_game_sdk::*;
/// # fn example(discord: Discord) -> Result<()> {
/// # let friend = User::from(discord_game_sdk_sys::DiscordUser::default());
/// # fn example(discord: Discord, friend: User) -> Result<()> {
/// discord.send_invite(
/// friend.id(),
/// Action::Join,
Expand Down
Loading

0 comments on commit eb2dcb7

Please sign in to comment.