diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cfd914..7b4b993 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,10 @@ jobs: - name: Install Formatting nightly uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2023-03-01 + toolchain: nightly-2023-07-09 components: rustfmt - name: Run Formatting check - run: cargo +nightly-2023-03-01 fmt --check --verbose + run: cargo +nightly-2023-07-09 fmt --check --verbose - name: Install MSRV uses: actions-rs/toolchain@v1 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb54f16..fea56bd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,10 +8,10 @@ repos: language: system files: '[.]rs$' pass_filenames: false - entry: rustup run --install nightly-2023-03-01 cargo-clippy -- -- -D warnings + entry: rustup run --install nightly-2023-07-09 cargo-clippy -- -- -D warnings - id: format name: Check rustfmt language: system files: '[.]rs$' pass_filenames: false - entry: rustup run --install nightly-2023-03-01 cargo-fmt --check + entry: rustup run --install nightly-2023-07-09 cargo-fmt --check diff --git a/.rustfmt.toml b/.rustfmt.toml index df854d3..313f091 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -48,7 +48,7 @@ overflow_delimited_expr = false reorder_impl_items = false reorder_imports = true reorder_modules = true -required_version = "1.5.2" +required_version = "1.6.0" short_array_element_width_threshold = 10 single_line_if_else_max_width = 50 skip_children = false diff --git a/VERSIONS.md b/VERSIONS.md index 3a00406..b64bf5a 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -9,7 +9,7 @@ Places to update: # rustfmt version -Current: `1.5.2` +Current: `1.6.0` Places to update: - `.rustfmt.toml` @@ -19,7 +19,7 @@ Places to update: The toolchain version used to run rustfmt in CI -Current: `nightly-2023-03-01` +Current: `nightly-2023-07-09` Places to update: - `./.github/workflows/ci.yml` diff --git a/src/errors.rs b/src/errors.rs index 0934cc7..80101a5 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,89 +1,89 @@ -use std::{ - error::Error, - fmt::{self, Formatter}, -}; - -/// Result of Type and GDError. -pub type GDResult = Result; - -/// GameDig Error. -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum GDError { - /// The received packet was bigger than the buffer size. - PacketOverflow, - /// The received packet was shorter than the expected one. - PacketUnderflow, - /// The received packet is badly formatted. - PacketBad, - /// Couldn't send the packet. - PacketSend, - /// Couldn't send the receive. - PacketReceive, - /// Couldn't decompress data. - Decompress, - /// Couldn't create a socket connection. - SocketConnect, - /// Couldn't bind a socket. - SocketBind, - /// Invalid input. - InvalidInput, - /// The server queried is not the queried game server. - BadGame(String), - /// Couldn't automatically query. - AutoQuery, - /// A protocol-defined expected format was not met. - ProtocolFormat, - /// Couldn't cast a value to an enum. - UnknownEnumCast, - /// Couldn't parse a json string. - JsonParse, - /// Couldn't parse a value. - TypeParse, -} - -impl Error for GDError {} - -impl fmt::Display for GDError { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } -} - -#[cfg(test)] -mod tests { - use super::*; - - // Testing Ok variant of the GDResult type - #[test] - fn test_gdresult_ok() { - let result: GDResult = Ok(42); - assert_eq!(result.unwrap(), 42); - } - - // Testing Err variant of the GDResult type - #[test] - fn test_gdresult_err() { - let result: GDResult = Err(GDError::InvalidInput); - assert!(result.is_err()); - } - - // Testing the Display trait for the GDError type - #[test] - fn test_display() { - let error = GDError::PacketOverflow; - assert_eq!(format!("{}", error), "PacketOverflow"); - } - - // Testing the Error trait for the GDError type - #[test] - fn test_error_trait() { - let error = GDError::PacketBad; - assert!(error.source().is_none()); - } - - // Testing cloning the GDError type - #[test] - fn test_cloning() { - let error = GDError::BadGame(String::from("MyGame")); - let cloned_error = error.clone(); - assert_eq!(error, cloned_error); - } -} +use std::{ + error::Error, + fmt::{self, Formatter}, +}; + +/// Result of Type and GDError. +pub type GDResult = Result; + +/// GameDig Error. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum GDError { + /// The received packet was bigger than the buffer size. + PacketOverflow, + /// The received packet was shorter than the expected one. + PacketUnderflow, + /// The received packet is badly formatted. + PacketBad, + /// Couldn't send the packet. + PacketSend, + /// Couldn't send the receive. + PacketReceive, + /// Couldn't decompress data. + Decompress, + /// Couldn't create a socket connection. + SocketConnect, + /// Couldn't bind a socket. + SocketBind, + /// Invalid input. + InvalidInput, + /// The server queried is not the queried game server. + BadGame(String), + /// Couldn't automatically query. + AutoQuery, + /// A protocol-defined expected format was not met. + ProtocolFormat, + /// Couldn't cast a value to an enum. + UnknownEnumCast, + /// Couldn't parse a json string. + JsonParse, + /// Couldn't parse a value. + TypeParse, +} + +impl Error for GDError {} + +impl fmt::Display for GDError { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } +} + +#[cfg(test)] +mod tests { + use super::*; + + // Testing Ok variant of the GDResult type + #[test] + fn test_gdresult_ok() { + let result: GDResult = Ok(42); + assert_eq!(result.unwrap(), 42); + } + + // Testing Err variant of the GDResult type + #[test] + fn test_gdresult_err() { + let result: GDResult = Err(GDError::InvalidInput); + assert!(result.is_err()); + } + + // Testing the Display trait for the GDError type + #[test] + fn test_display() { + let error = GDError::PacketOverflow; + assert_eq!(format!("{}", error), "PacketOverflow"); + } + + // Testing the Error trait for the GDError type + #[test] + fn test_error_trait() { + let error = GDError::PacketBad; + assert!(error.source().is_none()); + } + + // Testing cloning the GDError type + #[test] + fn test_cloning() { + let error = GDError::BadGame(String::from("MyGame")); + let cloned_error = error.clone(); + assert_eq!(error, cloned_error); + } +}