diff --git a/chunkify/src/impl.rs b/chunkify/src/impl.rs index ed930c4e..4740c4ab 100644 --- a/chunkify/src/impl.rs +++ b/chunkify/src/impl.rs @@ -44,7 +44,7 @@ impl fmt::Display for ChunkStrategyError { } /// Marks ChunkStrategyError as a standard error type. -impl std::error::Error for ChunkStrategyError {} +impl error::Error for ChunkStrategyError {} /// Converts ChunkStrategyError to a byte vector. /// @@ -231,7 +231,7 @@ impl<'a> HandleStrategy<'a> for ChunkStrategy<'a> { for i in *self.get_start_chunk_index()..*self.get_total_chunks() { let chunk_path: String = self.get_chunk_path(self.get_file_id(), i); let chunk_data: Vec = async_read_from_file(&chunk_path).await.map_err( - |error: Box| { + |error: Box| { ChunkStrategyError::ReadChunk(format!( "Failed to read chunk from {chunk_path}: {error}" )) diff --git a/chunkify/src/lib.rs b/chunkify/src/lib.rs index 771b492e..9268e08e 100644 --- a/chunkify/src/lib.rs +++ b/chunkify/src/lib.rs @@ -15,7 +15,7 @@ pub use {r#const::*, r#enum::*, r#struct::*, r#trait::*, r#type::*}; use r#static::*; use std::{ - fmt, + error, fmt, fs::{self, File, OpenOptions}, hash::BuildHasherDefault, io::{BufWriter, Error, Write}, diff --git a/chunkify/src/trait.rs b/chunkify/src/trait.rs index dfbc783e..89b6dbcc 100644 --- a/chunkify/src/trait.rs +++ b/chunkify/src/trait.rs @@ -18,7 +18,7 @@ pub trait HandleStrategy<'a>: Send + Sync { /// /// # Returns /// - /// - `impl Future` - Future of the save operation. fn save_chunk( &self, chunk_data: &'a [u8], @@ -29,6 +29,6 @@ pub trait HandleStrategy<'a>: Send + Sync { /// /// # Returns /// - /// - `impl Future` - Future of the merge operation. fn merge_chunks(&self) -> impl Future + Send; } diff --git a/color-output/src/color/impl.rs b/color-output/src/color/impl.rs index 8d9b6167..8952b784 100644 --- a/color-output/src/color/impl.rs +++ b/color-output/src/color/impl.rs @@ -499,9 +499,9 @@ impl<'a> ColorOutputList<'a> { /// Provides an iterator over the elements in the internal `Vec>`. /// /// # Returns - /// - `std::slice::Iter<'_, ColorOutput<'a>>` - An iterator over references to `ColorOutput` elements. + /// - `Iter<'_, ColorOutput<'a>>` - An iterator over references to `ColorOutput` elements. #[inline(always)] - pub fn iter(&self) -> std::slice::Iter<'_, ColorOutput<'a>> { + pub fn iter(&self) -> Iter<'_, ColorOutput<'a>> { self.0.iter() } diff --git a/color-output/src/lib.rs b/color-output/src/lib.rs index 6b779455..2ee83154 100644 --- a/color-output/src/lib.rs +++ b/color-output/src/lib.rs @@ -19,6 +19,8 @@ use std::{ borrow::Cow, fmt::{self, Display}, io::Write, + io::stdout, ops::Deref, slice::Iter, + str::Lines, }; diff --git a/color-output/src/task/impl.rs b/color-output/src/task/impl.rs index 6c2ead05..2422c057 100644 --- a/color-output/src/task/impl.rs +++ b/color-output/src/task/impl.rs @@ -54,7 +54,7 @@ impl<'a> Task<'a> { output_str.push_str(&Text::new_from(text).get_display_str_cow()); } print!("{output_str}"); - std::io::stdout().flush().unwrap(); + stdout().flush().unwrap(); self } } diff --git a/color-output/src/utils/fn.rs b/color-output/src/utils/fn.rs index fa09e94f..562b4359 100644 --- a/color-output/src/utils/fn.rs +++ b/color-output/src/utils/fn.rs @@ -17,7 +17,7 @@ pub fn __println_text(color: ColorType, bg_color: ColorType, text: &str) { .color(color) .bg_color(bg_color) .build(); - let lines: std::str::Lines<'_> = text.lines(); + let lines: Lines<'_> = text.lines(); for line in lines { let mut output_list_builder: ColorOutputListBuilder<'_> = ColorOutputListBuilder::new(); output_list_builder.add(time_output); diff --git a/compare-version/src/impl.rs b/compare-version/src/impl.rs index 44e79fd1..ee932aa6 100644 --- a/compare-version/src/impl.rs +++ b/compare-version/src/impl.rs @@ -37,7 +37,7 @@ impl Version { pub(crate) fn parse(version: &str) -> Result { let mut parts: Vec<&str> = version.split('.').collect(); let (patch_part, pre_release) = if let Some(patch_with_prerelease) = parts.pop() { - let mut patch_parts: std::str::SplitN<'_, char> = patch_with_prerelease.splitn(2, '-'); + let mut patch_parts: SplitN<'_, char> = patch_with_prerelease.splitn(2, '-'); ( patch_parts.next().unwrap_or(""), patch_parts.next().map(|part: &str| part.to_string()), @@ -49,15 +49,15 @@ impl Version { .first() .unwrap_or(&"0") .parse::() - .map_err(|_: std::num::ParseIntError| VersionError::MajorVersionError)?; + .map_err(|_: ParseIntError| VersionError::MajorVersionError)?; let minor: u32 = parts .get(1) .unwrap_or(&"0") .parse::() - .map_err(|_: std::num::ParseIntError| VersionError::MinorVersionError)?; + .map_err(|_: ParseIntError| VersionError::MinorVersionError)?; let patch: u32 = patch_part .parse::() - .map_err(|_: std::num::ParseIntError| VersionError::PatchVersionError)?; + .map_err(|_: ParseIntError| VersionError::PatchVersionError)?; Ok(Self { major, minor, @@ -82,9 +82,9 @@ impl CompareVersion { let v1: Version = Version::parse(version1)?; let v2: Version = Version::parse(version2)?; match v1.cmp(&v2) { - std::cmp::Ordering::Greater => Ok(VersionLevel::Greater), - std::cmp::Ordering::Less => Ok(VersionLevel::Less), - std::cmp::Ordering::Equal => Ok(VersionLevel::Equal), + Ordering::Greater => Ok(VersionLevel::Greater), + Ordering::Less => Ok(VersionLevel::Less), + Ordering::Equal => Ok(VersionLevel::Equal), } } diff --git a/compare-version/src/lib.rs b/compare-version/src/lib.rs index d86f96c8..547800aa 100644 --- a/compare-version/src/lib.rs +++ b/compare-version/src/lib.rs @@ -12,4 +12,4 @@ pub use {r#enum::*, r#struct::*}; use r#const::*; -use std::fmt; +use std::{cmp::Ordering, fmt, num::ParseIntError, str::SplitN}; diff --git a/crate-cli/src/bump/fn.rs b/crate-cli/src/bump/fn.rs index 2e602bbf..3e2969bd 100644 --- a/crate-cli/src/bump/fn.rs +++ b/crate-cli/src/bump/fn.rs @@ -190,7 +190,7 @@ fn expand_member_entry(root_dir: &Path, entry: &str) -> Vec { match entry.strip_suffix("/*") { Some(prefix) => { let mut dirs: Vec = Vec::new(); - if let Ok(entries) = std::fs::read_dir(root_dir.join(prefix)) { + if let Ok(entries) = fs::read_dir(root_dir.join(prefix)) { for entry in entries.flatten() { let path: PathBuf = entry.path(); if path.is_dir() && path.join(CARGO_TOML).exists() { @@ -270,12 +270,12 @@ fn realign_dep_versions( /// /// # Returns /// -/// - `Result<(), Box>` - Success or error +/// - `Result<(), Box>` - Success or error async fn realign_member_manifest( member_dir: &Path, member_manifest_path: &Path, bumped: &[(PathBuf, String)], -) -> Result<(), Box> { +) -> Result<(), Box> { let member_content: String = read_to_string(member_manifest_path).await?; let mut member_doc: DocumentMut = member_content.parse().map_err(|e: TomlError| { format!("failed to parse {}: {}", member_manifest_path.display(), e) @@ -344,12 +344,12 @@ async fn realign_member_manifest( /// /// # Returns /// -/// - `Result>` - Summary string +/// - `Result>` - Summary string async fn bump_workspace_members( root_path: &Path, doc: &mut DocumentMut, bump_type: &BumpVersionType, -) -> Result> { +) -> Result> { let root_dir: &Path = root_path.parent().unwrap_or_else(|| Path::new(".")); let member_entries: Vec = doc .get(TOML_WORKSPACE) @@ -387,7 +387,7 @@ async fn bump_workspace_members( let version_slot: &mut Item = member_doc .get_mut(TOML_PACKAGE) .and_then(|package: &mut Item| package.get_mut(TOML_VERSION)) - .ok_or_else(|| -> Box { + .ok_or_else(|| -> Box { format!( "package.version not found in {}", member_manifest_path.display() @@ -397,11 +397,10 @@ async fn bump_workspace_members( let Some(old_version) = version_slot.as_str().map(|s: &str| s.to_string()) else { continue; }; - let new_version: String = bump_version_str(&old_version, bump_type).ok_or_else( - || -> Box { + let new_version: String = + bump_version_str(&old_version, bump_type).ok_or_else(|| -> Box { format!("failed to parse version: {}", old_version).into() - }, - )?; + })?; set_item_string_preserving_decor(version_slot, &new_version); write(&member_manifest_path, member_doc.to_string()).await?; log::info!( @@ -451,12 +450,12 @@ async fn bump_workspace_members( /// /// # Returns /// -/// - `Result>` - The new version string, a +/// - `Result>` - The new version string, a /// workspace bump summary, or an error pub async fn execute_bump( manifest_path: &str, bump_type: &BumpVersionType, -) -> Result> { +) -> Result> { let path: &Path = Path::new(manifest_path); let content: String = read_to_string(path).await?; let mut doc: DocumentMut = content @@ -480,24 +479,21 @@ pub async fn execute_bump( doc.get_mut(TOML_WORKSPACE) .and_then(|workspace: &mut Item| workspace.get_mut(TOML_PACKAGE)) .and_then(|package: &mut Item| package.get_mut(TOML_VERSION)) - .ok_or_else(|| -> Box { - ERROR_WORKSPACE_PACKAGE_VERSION_MISSING.into() - })? + .ok_or_else(|| -> Box { ERROR_WORKSPACE_PACKAGE_VERSION_MISSING.into() })? } else if has_root_package { doc.get_mut(TOML_PACKAGE) .and_then(|package: &mut Item| package.get_mut(TOML_VERSION)) - .ok_or_else(|| -> Box { ERROR_PACKAGE_VERSION_MISSING.into() })? + .ok_or_else(|| -> Box { ERROR_PACKAGE_VERSION_MISSING.into() })? } else { return Err(ERROR_NO_VERSION_SLOT.into()); }; let version_str: String = version_slot .as_str() - .ok_or_else(|| -> Box { ERROR_VERSION_NOT_STRING.into() })? + .ok_or_else(|| -> Box { ERROR_VERSION_NOT_STRING.into() })? .to_string(); - let version: Version = - parse_version(&version_str).ok_or_else(|| -> Box { - format!("failed to parse version: {}", version_str).into() - })?; + let version: Version = parse_version(&version_str).ok_or_else(|| -> Box { + format!("failed to parse version: {}", version_str).into() + })?; let bumped: Version = bump_version(&version, bump_type); let version_string: String = version_to_string(&bumped); set_item_string_preserving_decor(version_slot, &version_string); diff --git a/crate-cli/src/fmt/fn.rs b/crate-cli/src/fmt/fn.rs index 4f5c875a..f24906fb 100644 --- a/crate-cli/src/fmt/fn.rs +++ b/crate-cli/src/fmt/fn.rs @@ -34,7 +34,7 @@ fn sort_derive_in_line(line: &str) -> Option { /// - `Result` - True if file was modified, false otherwise async fn format_derive_in_file(file_path: &Path) -> Result { let content: String = read_to_string(file_path).await?; - let lines: std::str::Lines<'_> = content.lines(); + let lines: Lines<'_> = content.lines(); let mut modified: bool = false; let mut new_content: String = String::new(); for line in lines { @@ -169,7 +169,7 @@ fn is_cargo_clippy_installed() -> bool { /// - `Result<(), io::Error>` - Success or error async fn install_cargo_clippy() -> Result<(), io::Error> { log::warn!("cargo-clippy not found, installing..."); - let output: std::process::Output = Command::new(RUSTUP) + let output: Output = Command::new(RUSTUP) .arg(RUSTUP_COMPONENT) .arg("add") .arg(CLIPPY) @@ -230,7 +230,7 @@ async fn execute_clippy_fix(args: &Args) -> Result<(), io::Error> { cmd.arg(CLI_FLAG_MANIFEST_PATH).arg(manifest_path); } cmd.stdout(Stdio::piped()).stderr(Stdio::piped()); - let output: std::process::Output = cmd.output().await?; + let output: Output = cmd.output().await?; let stdout: String = String::from_utf8_lossy(&output.stdout).trim().to_string(); let stderr: String = String::from_utf8_lossy(&output.stderr).trim().to_string(); if !stdout.is_empty() { @@ -287,7 +287,7 @@ pub async fn execute_fmt(args: &Args) -> Result<(), io::Error> { cmd.arg(CLI_FLAG_MANIFEST_PATH).arg(manifest_path); } cmd.stdout(Stdio::piped()).stderr(Stdio::piped()); - let output: std::process::Output = cmd.output().await?; + let output: Output = cmd.output().await?; let stdout: String = String::from_utf8_lossy(&output.stdout).trim().to_string(); let stderr: String = String::from_utf8_lossy(&output.stderr).trim().to_string(); if !stdout.is_empty() { diff --git a/crate-cli/src/lib.rs b/crate-cli/src/lib.rs index 2978f865..fad0cfe9 100644 --- a/crate-cli/src/lib.rs +++ b/crate-cli/src/lib.rs @@ -52,3 +52,8 @@ pub(crate) use { toml_edit::{DocumentMut, Item, TableLike, TomlError, value}, which::which, }; + +use std::{ + error::Error, fmt::Arguments, fs, process::Output, str::Lines, str::Split, + str::SplitWhitespace, time::SystemTime, time::UNIX_EPOCH, +}; diff --git a/crate-cli/src/logger/impl.rs b/crate-cli/src/logger/impl.rs index 36933454..45aa03f2 100644 --- a/crate-cli/src/logger/impl.rs +++ b/crate-cli/src/logger/impl.rs @@ -26,7 +26,7 @@ impl log::Log for Logger { } let now_time: String = color_output::time(); let level: log::Level = record.level(); - let args: &std::fmt::Arguments<'_> = record.args(); + let args: &Arguments<'_> = record.args(); let file: Option<&str> = record.file(); let module_path: Option<&str> = record.module_path(); let target: &str = record.target(); diff --git a/crate-cli/src/publish/fn.rs b/crate-cli/src/publish/fn.rs index 482391fb..4f695a45 100644 --- a/crate-cli/src/publish/fn.rs +++ b/crate-cli/src/publish/fn.rs @@ -422,7 +422,7 @@ pub fn parse_rate_limit_wait_secs(stderr: &str) -> Option { let start: usize = stderr.find(STDERR_TRY_AGAIN_AFTER)? + STDERR_TRY_AGAIN_AFTER.len(); let end: usize = start + stderr[start..].find(STDERR_TRY_AGAIN_AFTER_END)?; let timestamp: &str = stderr[start..end].trim(); - let mut tokens: std::str::SplitWhitespace<'_> = timestamp.split_whitespace(); + let mut tokens: SplitWhitespace<'_> = timestamp.split_whitespace(); let _: &str = tokens.next()?; let day: i64 = tokens .next()? @@ -435,16 +435,13 @@ pub fn parse_rate_limit_wait_secs(stderr: &str) -> Option { .position(|name: &&str| *name == month_token)? as i64 + 1; let year: i64 = tokens.next()?.parse().ok()?; - let mut clock_fields: std::str::Split<'_, char> = tokens.next()?.split(CLOCK_FIELD_SEPARATOR); + let mut clock_fields: Split<'_, char> = tokens.next()?.split(CLOCK_FIELD_SEPARATOR); let hour: i64 = clock_fields.next()?.parse().ok()?; let minute: i64 = clock_fields.next()?.parse().ok()?; let second: i64 = clock_fields.next()?.parse().ok()?; let day_start: i64 = civil_to_days(year, month, day) * SECONDS_PER_DAY; let deadline: i64 = day_start + hour * SECONDS_PER_HOUR + minute * SECONDS_PER_MINUTE + second; - let now: i64 = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .ok()? - .as_secs() as i64; + let now: i64 = SystemTime::now().duration_since(UNIX_EPOCH).ok()?.as_secs() as i64; let remaining: i64 = deadline - now; // A parsed deadline is honoured as given, in either direction: a window // the registry says is shorter than the skew allowance is already open @@ -538,9 +535,9 @@ async fn publish_package_with_retry(package: &Package, max_retries: u32) -> Publ /// /// # Returns /// -/// - `Result<(), Box>` - Success or error -async fn publish_single_package(package: &Package) -> Result<(), Box> { - let output: std::process::Output = Command::new(CARGO) +/// - `Result<(), Box>` - Success or error +async fn publish_single_package(package: &Package) -> Result<(), Box> { + let output: Output = Command::new(CARGO) .arg(CARGO_PUBLISH) .arg(CLI_FLAG_ALLOW_DIRTY) .arg(CLI_FLAG_NO_VERIFY) diff --git a/crate-cli/tests/bump/fn.rs b/crate-cli/tests/bump/fn.rs index 1dedc7c2..546b0b7b 100644 --- a/crate-cli/tests/bump/fn.rs +++ b/crate-cli/tests/bump/fn.rs @@ -51,7 +51,7 @@ version = "0.1.0" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Patch).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "0.1.1"); @@ -70,7 +70,7 @@ version = "0.1.0" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Minor).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "0.2.0"); @@ -87,7 +87,7 @@ version = "0.1.0" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Major).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "1.0.0"); @@ -104,7 +104,7 @@ version = "0.1.0" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Alpha).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "0.1.0-alpha"); @@ -121,7 +121,7 @@ version = "0.1.0-alpha.2" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Beta).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "0.1.0-beta.1"); @@ -138,7 +138,7 @@ version = "0.1.0-beta.1" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Rc).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "0.1.0-rc.1"); @@ -155,7 +155,7 @@ version = "0.1.0-alpha" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Release).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "0.1.0"); @@ -171,7 +171,7 @@ name = "test-package" edition = "2024" "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Patch).await; assert!(result.is_err()); } @@ -214,7 +214,7 @@ serde = { version = "1.0.229", features = ["derive"] } opt-level = 3 "#; write(&manifest_path, content).await.unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Patch).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "21.5.3"); @@ -259,7 +259,7 @@ edition = "2024" write(tmp_dir.join("beta/Cargo.toml"), beta_content) .await .unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Minor).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "2 workspace members"); @@ -327,7 +327,7 @@ members = ["crates/*"] .await .unwrap(); } - let result: Result> = execute_bump( + let result: Result> = execute_bump( tmp_dir.join("Cargo.toml").to_str().unwrap(), &BumpVersionType::Patch, ) @@ -365,7 +365,7 @@ edition.workspace = true write(tmp_dir.join("core/Cargo.toml"), core_content) .await .unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Patch).await; assert!(result.is_ok()); assert_eq!(result.unwrap(), "21.7.1"); @@ -399,7 +399,7 @@ edition = "2024" write(tmp_dir.join("b/Cargo.toml"), b_content) .await .unwrap(); - let result: Result> = execute_bump( + let result: Result> = execute_bump( tmp_dir.join("Cargo.toml").to_str().unwrap(), &BumpVersionType::Patch, ) @@ -420,7 +420,7 @@ async fn test_execute_bump_empty_workspace_without_package_errors() { write(&manifest_path, "[workspace]\nmembers = []\n") .await .unwrap(); - let result: Result> = + let result: Result> = execute_bump(manifest_path.to_str().unwrap(), &BumpVersionType::Patch).await; assert!(result.is_err()); } @@ -441,7 +441,7 @@ async fn test_execute_bump_virtual_workspace_prerelease_members() { ) .await .unwrap(); - let result: Result> = execute_bump( + let result: Result> = execute_bump( tmp_dir.join("Cargo.toml").to_str().unwrap(), &BumpVersionType::Alpha, ) diff --git a/crate-cli/tests/mod.rs b/crate-cli/tests/mod.rs index 46b711b7..0f1c1675 100644 --- a/crate-cli/tests/mod.rs +++ b/crate-cli/tests/mod.rs @@ -9,6 +9,7 @@ use crate_cli::*; use std::{ env::temp_dir, + error, io::{self, Error}, path::{Path, PathBuf}, }; diff --git a/crate-cli/tests/publish/fn.rs b/crate-cli/tests/publish/fn.rs index c2eda23f..c70c5e67 100644 --- a/crate-cli/tests/publish/fn.rs +++ b/crate-cli/tests/publish/fn.rs @@ -253,20 +253,10 @@ fn test_is_already_published() { #[test] fn test_is_already_published_matches_live_cargo_message() { - // Verbatim from cargo 1.98.1 — the template is - // `crate {name}@{version} already exists on {registry}` — which is the - // toolchain `dtolnay/rust-toolchain@stable` resolves to in CI. The other - // two markers are worded for older toolchains and no longer appear in - // this binary, so without this case a re-run fails on every crate that - // has already shipped. let default_registry: &str = "error: failed to publish stripe-pay-core v10.2.2 to registry at https://github.com/rust-lang/crates.io-index\n\nCaused by:\n crate stripe-pay-core@10.2.2 already exists on crates.io\n"; assert!(is_already_published(default_registry)); - // The clause is matched, not the registry name, so a renamed registry or - // a sparse source replacement is covered by the same marker. let renamed_registry: &str = "error: failed to publish bin-encode-decode v10.2.2 to registry at sparse+https://index.crates.io/\n\nCaused by:\n crate bin-encode-decode@10.2.2 already exists on registry `crates-io`\n"; assert!(is_already_published(renamed_registry)); - // Near-misses must not be swallowed: a dependency-source fault and a - // ban are real failures and have to keep reporting as ones. assert!(!is_already_published( "error: crates cannot be published to crates.io with dependencies sourced from other registries" )); @@ -291,9 +281,6 @@ fn test_is_rate_limited() { fn test_parse_rate_limit_wait_secs_reads_registry_deadline() { let stderr: &str = "error: failed to publish stripe-pay-core v10.2.2 to registry at https://crates.io\n\nCaused by:\n the remote server responded with an error (status 429 Too Many Requests): You have published too many new crates in a short period of time. Please try again after Tue, 29 Sep 2026 04:55:57 GMT and see https://crates.io/docs/rate-limits for more details.\n"; let wait: u64 = parse_rate_limit_wait_secs(stderr).unwrap(); - // The deadline is honoured, not replaced: this timestamp is in the past - // relative to a test run, so only the skew allowance remains. The - // interval is asserted by the near-deadline case, not forced here. assert!(wait <= 11 * 60); assert!(wait >= 30); } @@ -319,10 +306,6 @@ fn test_parse_rate_limit_wait_secs_clamps_a_far_future_deadline() { #[test] fn test_parse_rate_limit_wait_secs_keeps_a_near_deadline_short() { - // The registry's own interval is about ten minutes, so a deadline in the - // past or a couple of seconds out is the case the fallback used to mask: - // the old floor stretched every parsed window up to eleven minutes. A - // deadline that has already passed must return only the skew allowance. let past: u64 = parse_rate_limit_wait_secs("Please try again after Tue, 29 Sep 2020 04:55:57 GMT").unwrap(); assert_eq!( @@ -340,9 +323,6 @@ fn test_parse_rate_limit_wait_secs_absent_deadline() { #[test] fn test_parse_rate_limit_wait_secs_honours_a_parsed_deadline() { - // An unparseable refusal has no deadline to honour, so the caller falls - // back to one full refill interval. The floor applies there and nowhere - // else: a parsed deadline shorter than it is still taken at face value. let readable: u64 = parse_rate_limit_wait_secs("Please try again after Tue, 29 Sep 2026 04:55:57 GMT").unwrap(); assert!(readable <= 11 * 60); diff --git a/file-operation/src/copy/sync/fn.rs b/file-operation/src/copy/sync/fn.rs index 2e016eee..edafd3c3 100644 --- a/file-operation/src/copy/sync/fn.rs +++ b/file-operation/src/copy/sync/fn.rs @@ -11,7 +11,7 @@ use super::*; /// /// - `Result<(), Error>` - Ok if the file was copied successfully, Err with error details otherwise. pub fn copy_file(src: &str, dest: &str) -> Result<(), Error> { - std::fs::copy(src, dest)?; + copy(src, dest)?; Ok(()) } @@ -38,8 +38,8 @@ pub fn copy_dir_files(src_dir: &str, dest_dir: &str) -> Result<(), Error> { delete_dir(dest_path_str)?; } } - std::fs::create_dir_all(dest_path)?; - for entry in std::fs::read_dir(src_path)? { + create_dir_all(dest_path)?; + for entry in read_dir(src_path)? { let entry: DirEntry = entry?; let file_name: OsString = entry.file_name(); let src_file_path: PathBuf = entry.path(); @@ -51,7 +51,7 @@ pub fn copy_dir_files(src_dir: &str, dest_dir: &str) -> Result<(), Error> { dest_file_path.to_str().unwrap(), )?; } else if src_file_path.is_file() { - std::fs::copy(&src_file_path, &dest_file_path)?; + copy(&src_file_path, &dest_file_path)?; } } Ok(()) diff --git a/file-operation/src/delete/sync/fn.rs b/file-operation/src/delete/sync/fn.rs index d127145f..8da71e99 100644 --- a/file-operation/src/delete/sync/fn.rs +++ b/file-operation/src/delete/sync/fn.rs @@ -10,7 +10,7 @@ use super::*; /// /// - `Result<(), Error>` - Ok if the file was deleted successfully, Err with error details otherwise. pub fn delete_file(path: &str) -> Result<(), Error> { - std::fs::remove_file(path) + remove_file(path) } /// Deletes a directory and all its contents. @@ -24,6 +24,6 @@ pub fn delete_file(path: &str) -> Result<(), Error> { /// - `Result<(), Error>` - Ok if the directory was deleted successfully, Err with error details otherwise. pub fn delete_dir(path: &str) -> Result<(), Error> { let dir_path: &Path = Path::new(path); - std::fs::remove_dir_all(dir_path)?; + remove_dir_all(dir_path)?; Ok(()) } diff --git a/file-operation/src/file/impl.rs b/file-operation/src/file/impl.rs index a8098ae5..36deb9f7 100644 --- a/file-operation/src/file/impl.rs +++ b/file-operation/src/file/impl.rs @@ -12,9 +12,7 @@ impl From> for FileDataString { /// /// - `FileDataString` - The converted string wrapper. fn from(bytes: Vec) -> Self { - FileDataString( - String::from_utf8(bytes).unwrap_or_else(|_: std::string::FromUtf8Error| String::new()), - ) + FileDataString(String::from_utf8(bytes).unwrap_or_else(|_: FromUtf8Error| String::new())) } } diff --git a/file-operation/src/lib.rs b/file-operation/src/lib.rs index 5d1554d0..afe07b7f 100644 --- a/file-operation/src/lib.rs +++ b/file-operation/src/lib.rs @@ -14,12 +14,27 @@ mod write; pub use {copy::*, delete::*, file::*, r#move::*, read::*, write::*}; use std::{ + error, ffi::OsString, fmt, fs::DirEntry, + fs::File, + fs::Metadata, + fs::OpenOptions, + fs::copy, + fs::create_dir_all, + fs::metadata, + fs::read_dir, + fs::remove_dir, + fs::remove_dir_all, + fs::remove_file, + fs::rename, io::Error, + io::Read, + io::Write, path::{Path, PathBuf}, pin::Pin, + string::FromUtf8Error, }; use tokio::{fs::ReadDir, spawn, task::JoinHandle}; diff --git a/file-operation/src/move/async/fn.rs b/file-operation/src/move/async/fn.rs index 23a5c986..a9b70402 100644 --- a/file-operation/src/move/async/fn.rs +++ b/file-operation/src/move/async/fn.rs @@ -24,7 +24,7 @@ pub async fn async_move_file(src: &str, dest: &str) -> Result<(), Error> { /// /// # Returns /// -/// - `Pin> + 'a>>` - A pinned boxed future that resolves to the move operation result. pub fn async_move_dir<'a>( src_dir: &'a str, dest_dir: &'a str, diff --git a/file-operation/src/move/sync/fn.rs b/file-operation/src/move/sync/fn.rs index acdc8195..259c2d66 100644 --- a/file-operation/src/move/sync/fn.rs +++ b/file-operation/src/move/sync/fn.rs @@ -11,7 +11,7 @@ use super::*; /// /// - `Result<(), Error>` - Ok if the file was moved successfully, Err with error details otherwise. pub fn move_file(src: &str, dest: &str) -> Result<(), Error> { - std::fs::rename(src, dest)?; + rename(src, dest)?; Ok(()) } @@ -29,11 +29,11 @@ pub fn move_dir(src_dir: &str, dest_dir: &str) -> Result<(), Error> { let src_path: &Path = Path::new(src_dir); let dest_path: &Path = Path::new(dest_dir); if dest_path.exists() { - std::fs::remove_dir_all(dest_path)?; + remove_dir_all(dest_path)?; } - std::fs::create_dir_all(dest_path)?; - for entry in std::fs::read_dir(src_path)? { - let entry: std::fs::DirEntry = entry?; + create_dir_all(dest_path)?; + for entry in read_dir(src_path)? { + let entry: DirEntry = entry?; let file_name: OsString = entry.file_name(); let src_file_path: PathBuf = entry.path(); let mut dest_file_path: PathBuf = PathBuf::from(dest_path); @@ -44,9 +44,9 @@ pub fn move_dir(src_dir: &str, dest_dir: &str) -> Result<(), Error> { dest_file_path.to_str().unwrap(), )?; } else if src_file_path.is_file() { - std::fs::rename(&src_file_path, &dest_file_path)?; + rename(&src_file_path, &dest_file_path)?; } } - std::fs::remove_dir(src_path)?; + remove_dir(src_path)?; Ok(()) } diff --git a/file-operation/src/read/async/fn.rs b/file-operation/src/read/async/fn.rs index 8c87442a..99e88a04 100644 --- a/file-operation/src/read/async/fn.rs +++ b/file-operation/src/read/async/fn.rs @@ -8,8 +8,8 @@ use super::*; /// /// # Returns /// -/// - `Result>` - The converted file content or an error. -pub async fn async_read_from_file(file_path: &str) -> Result> +/// - `Result>` - The converted file content or an error. +pub async fn async_read_from_file(file_path: &str) -> Result> where T: From>, { @@ -32,6 +32,6 @@ where pub async fn async_get_file_size(file_path: &str) -> Option { tokio::fs::metadata(file_path) .await - .map(|metadata: std::fs::Metadata| Some(metadata.len())) + .map(|metadata: Metadata| Some(metadata.len())) .unwrap_or(None) } diff --git a/file-operation/src/read/sync/fn.rs b/file-operation/src/read/sync/fn.rs index 15325760..2d9c285a 100644 --- a/file-operation/src/read/sync/fn.rs +++ b/file-operation/src/read/sync/fn.rs @@ -8,15 +8,15 @@ use super::*; /// /// # Returns /// -/// - `Result>` - The converted file content or an error. -pub fn read_from_file(file_path: &str) -> Result> +/// - `Result>` - The converted file content or an error. +pub fn read_from_file(file_path: &str) -> Result> where T: From>, { let path: &Path = Path::new(file_path); - let mut file: std::fs::File = std::fs::File::open(path)?; + let mut file: File = File::open(path)?; let mut content: Vec = Vec::new(); - std::io::Read::read_to_end(&mut file, &mut content)?; + Read::read_to_end(&mut file, &mut content)?; Ok(T::from(content)) } @@ -30,7 +30,7 @@ where /// /// - `Option` - The file size in bytes if successful, None otherwise. pub fn get_file_size(file_path: &str) -> Option { - std::fs::metadata(file_path) - .map(|metadata: std::fs::Metadata| Some(metadata.len())) + metadata(file_path) + .map(|metadata: Metadata| Some(metadata.len())) .unwrap_or(None) } diff --git a/file-operation/src/write/async/fn.rs b/file-operation/src/write/async/fn.rs index bcd8e8e2..d61c89c7 100644 --- a/file-operation/src/write/async/fn.rs +++ b/file-operation/src/write/async/fn.rs @@ -11,7 +11,7 @@ use super::*; /// /// - `Result<(), Error>` - Ok if successful, Err with error details otherwise. pub async fn async_write_to_file(file_path: &str, content: &[u8]) -> Result<(), Error> { - if let Some(parent_dir) = std::path::Path::new(file_path).parent() { + if let Some(parent_dir) = Path::new(file_path).parent() { tokio::fs::create_dir_all(parent_dir).await?; } let mut file: tokio::fs::File = tokio::fs::OpenOptions::new() @@ -35,7 +35,7 @@ pub async fn async_write_to_file(file_path: &str, content: &[u8]) -> Result<(), /// /// - `Result<(), Error>` - Ok if successful, Err with error details otherwise. pub async fn async_append_to_file(file_path: &str, content: &[u8]) -> Result<(), Error> { - if let Some(parent_dir) = std::path::Path::new(file_path).parent() { + if let Some(parent_dir) = Path::new(file_path).parent() { tokio::fs::create_dir_all(parent_dir).await?; } let mut file: tokio::fs::File = tokio::fs::OpenOptions::new() diff --git a/file-operation/src/write/sync/fn.rs b/file-operation/src/write/sync/fn.rs index f679deb5..4570d41e 100644 --- a/file-operation/src/write/sync/fn.rs +++ b/file-operation/src/write/sync/fn.rs @@ -11,15 +11,15 @@ use super::*; /// /// - `Result<(), Error>` - Ok if successful, Err with error details otherwise. pub fn write_to_file(file_path: &str, content: &[u8]) -> Result<(), Error> { - if let Some(parent_dir) = std::path::Path::new(file_path).parent() { - std::fs::create_dir_all(parent_dir)?; + if let Some(parent_dir) = Path::new(file_path).parent() { + create_dir_all(parent_dir)?; } - std::fs::OpenOptions::new() + OpenOptions::new() .write(true) .create(true) .truncate(true) .open(file_path) - .and_then(|mut file: std::fs::File| std::io::Write::write_all(&mut file, content)) + .and_then(|mut file: File| Write::write_all(&mut file, content)) } /// Appends content to a file. @@ -33,12 +33,12 @@ pub fn write_to_file(file_path: &str, content: &[u8]) -> Result<(), Error> { /// /// - `Result<(), Error>` - Ok if successful, Err with error details otherwise. pub fn append_to_file(file_path: &str, content: &[u8]) -> Result<(), Error> { - if let Some(parent_dir) = std::path::Path::new(file_path).parent() { - std::fs::create_dir_all(parent_dir)?; + if let Some(parent_dir) = Path::new(file_path).parent() { + create_dir_all(parent_dir)?; } - std::fs::OpenOptions::new() + OpenOptions::new() .create(true) .append(true) .open(file_path) - .and_then(|mut file: std::fs::File| std::io::Write::write_all(&mut file, content)) + .and_then(|mut file: File| Write::write_all(&mut file, content)) } diff --git a/file-operation/tests/file/fn.rs b/file-operation/tests/file/fn.rs index 3f4410b3..fe87f044 100644 --- a/file-operation/tests/file/fn.rs +++ b/file-operation/tests/file/fn.rs @@ -11,42 +11,42 @@ async fn test_write() { let size: Option = get_file_size(FILE_PATH); println!("read_from_file => {:?}", String::from_utf8_lossy(&res)); println!("get_file_size => {size:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = copy_dir_files(FILE_DIR, NEW_FILE_DIR); println!("copy_dir_files => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = delete_file(FILE_PATH); println!("delete_file => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = move_dir(FILE_DIR, NEW_TEST_DIR); println!("move_dir => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = delete_dir(NEW_TEST_DIR); println!("delete_dir => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = delete_dir(NEW_FILE_DIR); println!("delete_dir => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let _: Result<(), Error> = async_write_to_file(FILE_PATH, "test".as_bytes()).await; let res: Vec = async_read_from_file(FILE_PATH).await.unwrap_or_default(); let size: Option = async_get_file_size(FILE_PATH).await; println!("read_from_file => {:?}", String::from_utf8_lossy(&res)); println!("get_file_size => {size:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = async_copy_dir_files(FILE_DIR, NEW_FILE_DIR).await; println!("copy_dir_files => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = async_delete_file(FILE_PATH).await; - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); println!("delete_file => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = async_move_dir(FILE_DIR, NEW_TEST_DIR).await; println!("move_dir => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = async_delete_dir(NEW_TEST_DIR).await; println!("delete_dir => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); let res: Result<(), Error> = async_delete_dir(NEW_FILE_DIR).await; println!("delete_dir => {res:?}"); - std::thread::sleep(std::time::Duration::from_secs(2)); + sleep(Duration::from_secs(2)); } diff --git a/file-operation/tests/mod.rs b/file-operation/tests/mod.rs index 6833f792..dbdaadc8 100644 --- a/file-operation/tests/mod.rs +++ b/file-operation/tests/mod.rs @@ -2,4 +2,4 @@ mod file; use file_operation::*; -use std::io::Error; +use std::{io::Error, thread::sleep, time::Duration}; diff --git a/jwt-service/src/impl.rs b/jwt-service/src/impl.rs index 80b260f7..d4da2e73 100644 --- a/jwt-service/src/impl.rs +++ b/jwt-service/src/impl.rs @@ -111,7 +111,7 @@ impl ExtraJwtClaims { } /// Display implementation for JwtValidationError. -impl std::fmt::Display for JwtValidationError { +impl Display for JwtValidationError { /// Formats the validation error for display. /// /// # Arguments @@ -135,7 +135,7 @@ impl std::fmt::Display for JwtValidationError { } /// Error trait implementation for JwtValidationError. -impl std::error::Error for JwtValidationError {} +impl Error for JwtValidationError {} /// Conversion from jsonwebtoken errors to JwtValidationError. /// diff --git a/jwt-service/src/lib.rs b/jwt-service/src/lib.rs index 418ce116..c44c2834 100644 --- a/jwt-service/src/lib.rs +++ b/jwt-service/src/lib.rs @@ -16,6 +16,8 @@ use r#const::*; use std::{ collections::HashMap, + error::Error, + fmt::Display, time::{SystemTime, UNIX_EPOCH}, }; diff --git a/lombok-macros/src/visibility/impl.rs b/lombok-macros/src/visibility/impl.rs index 120d40bc..9fa4e269 100644 --- a/lombok-macros/src/visibility/impl.rs +++ b/lombok-macros/src/visibility/impl.rs @@ -39,7 +39,7 @@ impl Display for Visibility { /// Implementation of FromStr trait for Visibility enum. /// This allows parsing string representations back into Visibility variants. -impl std::str::FromStr for Visibility { +impl FromStr for Visibility { type Err = String; /// Parses a string into a `Visibility` enum variant. diff --git a/recoverable-spawn/src/lib.rs b/recoverable-spawn/src/lib.rs index c40d00fc..001b30ef 100644 --- a/recoverable-spawn/src/lib.rs +++ b/recoverable-spawn/src/lib.rs @@ -12,6 +12,8 @@ pub use {r#async::*, common::*, sync::*}; use std::{ any::Any, + panic::AssertUnwindSafe, + panic::catch_unwind, panic::{PanicHookInfo, set_hook}, sync::Arc, }; diff --git a/recoverable-spawn/src/sync/fn.rs b/recoverable-spawn/src/sync/fn.rs index 9248af40..34a179cf 100644 --- a/recoverable-spawn/src/sync/fn.rs +++ b/recoverable-spawn/src/sync/fn.rs @@ -11,7 +11,7 @@ use super::*; /// - `SyncSpawnResult` - The spawn operation result. pub fn run_function(func: F) -> SyncSpawnResult { set_hook(Box::new(move |_: &PanicHookInfo<'_>| {})); - std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + catch_unwind(AssertUnwindSafe(|| { func(); })) } @@ -28,7 +28,7 @@ pub fn run_function(func: F) -> SyncSpawnResult { /// - `SyncSpawnResult` - The spawn operation result. pub fn run_error_handle_function(func: E, error: &str) -> SyncSpawnResult { set_hook(Box::new(move |_: &PanicHookInfo<'_>| {})); - std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + catch_unwind(AssertUnwindSafe(|| { func(error); })) } diff --git a/recoverable-spawn/tests/async/fn.rs b/recoverable-spawn/tests/async/fn.rs index a02419e5..9a22223e 100644 --- a/recoverable-spawn/tests/async/fn.rs +++ b/recoverable-spawn/tests/async/fn.rs @@ -1,7 +1,5 @@ use super::*; -use std::sync::Arc; - #[tokio::test] async fn test_async_recoverable_spawn() { let msg: &str = "test"; diff --git a/recoverable-spawn/tests/mod.rs b/recoverable-spawn/tests/mod.rs index e0c7a372..c94380da 100644 --- a/recoverable-spawn/tests/mod.rs +++ b/recoverable-spawn/tests/mod.rs @@ -2,3 +2,5 @@ mod r#async; mod sync; use recoverable_spawn::*; + +use std::sync::Arc; diff --git a/recoverable-thread-pool/src/lib.rs b/recoverable-thread-pool/src/lib.rs index 5b85025f..55d801fe 100644 --- a/recoverable-thread-pool/src/lib.rs +++ b/recoverable-thread-pool/src/lib.rs @@ -14,7 +14,7 @@ use std::{ Arc, Mutex, mpsc::{self, Receiver, SendError, Sender}, }, - thread::spawn, + thread::{self, spawn}, }; use {lombok_macros::*, recoverable_spawn::*, tokio::runtime::Builder}; diff --git a/recoverable-thread-pool/src/thread_pool/impl.rs b/recoverable-thread-pool/src/thread_pool/impl.rs index d80e225c..d249601a 100644 --- a/recoverable-thread-pool/src/thread_pool/impl.rs +++ b/recoverable-thread-pool/src/thread_pool/impl.rs @@ -43,7 +43,7 @@ impl ThreadPool { F: RecoverableFunction, { let job_with_handler: ThreadPoolJob = Box::new(move || { - let _: std::thread::Result<()> = run_function(job); + let _: thread::Result<()> = run_function(job); }); self.get_sender().send(job_with_handler) } @@ -66,8 +66,7 @@ impl ThreadPool { let job_with_handler: ThreadPoolJob = Box::new(move || { if let Err(err) = run_function(job) { let err_string: String = spawn_error_to_string(&err); - let _: std::thread::Result<()> = - run_error_handle_function(handle_error, &err_string); + let _: thread::Result<()> = run_error_handle_function(handle_error, &err_string); } }); self.get_sender().send(job_with_handler) @@ -98,10 +97,9 @@ impl ThreadPool { let job_with_handler: ThreadPoolJob = Box::new(move || { if let Err(err) = run_function(job) { let err_string: String = spawn_error_to_string(&err); - let _: std::thread::Result<()> = - run_error_handle_function(handle_error, &err_string); + let _: thread::Result<()> = run_error_handle_function(handle_error, &err_string); } - let _: std::thread::Result<()> = run_function(finally); + let _: thread::Result<()> = run_function(finally); }); self.get_sender().send(job_with_handler) } diff --git a/recoverable-thread-pool/src/worker/impl.rs b/recoverable-thread-pool/src/worker/impl.rs index b5881983..89db933e 100644 --- a/recoverable-thread-pool/src/worker/impl.rs +++ b/recoverable-thread-pool/src/worker/impl.rs @@ -14,12 +14,12 @@ impl Worker { /// - `Option` - The new worker instance. pub fn new(id: usize, receiver: Arc>>) -> Option { spawn(|| { - let _: std::thread::Result<()> = recoverable_spawn(move || { + let _: thread::Result<()> = recoverable_spawn(move || { loop { if let Ok(receiver_lock) = receiver.lock() && let Ok(job) = receiver_lock.recv() { - let _: std::thread::Result<()> = recoverable_spawn(job); + let _: thread::Result<()> = recoverable_spawn(job); } } }); diff --git a/recoverable-thread-pool/tests/mod.rs b/recoverable-thread-pool/tests/mod.rs index beb066d3..abf11476 100644 --- a/recoverable-thread-pool/tests/mod.rs +++ b/recoverable-thread-pool/tests/mod.rs @@ -2,4 +2,4 @@ mod thread_pool; use recoverable_thread_pool::*; -use std::{thread::sleep, time::Duration}; +use std::{sync::Arc, thread::sleep, time::Duration}; diff --git a/recoverable-thread-pool/tests/thread_pool/fn.rs b/recoverable-thread-pool/tests/thread_pool/fn.rs index 83f028e1..08d8a6c8 100644 --- a/recoverable-thread-pool/tests/thread_pool/fn.rs +++ b/recoverable-thread-pool/tests/thread_pool/fn.rs @@ -1,6 +1,5 @@ use super::*; -use std::sync::Arc; #[test] fn test() { let thread_pool: ThreadPool = ThreadPool::new(1); diff --git a/server-manager/src/impl.rs b/server-manager/src/impl.rs index 55600a8e..4fb6840a 100644 --- a/server-manager/src/impl.rs +++ b/server-manager/src/impl.rs @@ -60,7 +60,7 @@ impl ServerManager { #[cfg(not(windows))] pub async fn start_daemon(&self) -> ServerManagerResult { (self.get_start_hook())().await; - if std::env::var(RUNNING_AS_DAEMON).is_ok() { + if var(RUNNING_AS_DAEMON).is_ok() { self.write_pid_file()?; let rt: Runtime = Runtime::new()?; rt.block_on(async { @@ -68,14 +68,14 @@ impl ServerManager { }); return Ok(()); } - let exe_path: PathBuf = std::env::current_exe()?; + let exe_path: PathBuf = current_exe()?; let mut cmd: Command = Command::new(exe_path); cmd.env(RUNNING_AS_DAEMON, RUNNING_AS_DAEMON_VALUE) .stdout(Stdio::null()) .stderr(Stdio::null()) .stdin(Stdio::null()); cmd.spawn() - .map_err(|error: Error| Box::new(error) as Box)?; + .map_err(|error: Error| Box::new(error) as Box)?; Ok(()) } @@ -87,7 +87,7 @@ impl ServerManager { #[cfg(windows)] pub async fn start_daemon(&self) -> ServerManagerResult { (self.get_start_hook())().await; - if std::env::var(RUNNING_AS_DAEMON).is_ok() { + if var(RUNNING_AS_DAEMON).is_ok() { self.write_pid_file()?; let rt: Runtime = Runtime::new()?; rt.block_on(async { @@ -95,7 +95,7 @@ impl ServerManager { }); return Ok(()); } - let exe_path: PathBuf = std::env::current_exe()?; + let exe_path: PathBuf = current_exe()?; let mut cmd: Command = Command::new(exe_path); cmd.env(RUNNING_AS_DAEMON, RUNNING_AS_DAEMON_VALUE) .stdout(Stdio::null()) @@ -103,7 +103,7 @@ impl ServerManager { .stdin(Stdio::null()) .creation_flags(0x00000008); cmd.spawn() - .map_err(|error: Error| Box::new(error) as Box)?; + .map_err(|error: Error| Box::new(error) as Box)?; Ok(()) } @@ -111,8 +111,8 @@ impl ServerManager { /// /// # Returns /// - /// - `Result>` - Process ID if successful. - fn read_pid_file(&self) -> Result> { + /// - `Result>` - Process ID if successful. + fn read_pid_file(&self) -> Result> { let pid_str: String = fs::read_to_string(self.get_pid_file())?; let pid: i32 = pid_str.trim().parse::()?; Ok(pid) @@ -281,11 +281,11 @@ impl ServerManager { .stdin(Stdio::inherit()); let mut child: Child = command .spawn() - .map_err(|error: Error| Box::new(error) as Box)?; + .map_err(|error: Error| Box::new(error) as Box)?; if wait { child .wait() - .map_err(|error: Error| Box::new(error) as Box)?; + .map_err(|error: Error| Box::new(error) as Box)?; } exit(0); } diff --git a/server-manager/src/lib.rs b/server-manager/src/lib.rs index 34874f7e..aaeb6c23 100644 --- a/server-manager/src/lib.rs +++ b/server-manager/src/lib.rs @@ -30,4 +30,5 @@ use std::{ #[cfg(windows)] use std::{ffi::c_void, os::windows::process::CommandExt}; +use std::{env::current_exe, env::var, error}; use {lombok_macros::*, tokio::runtime::Runtime}; diff --git a/server-manager/src/type.rs b/server-manager/src/type.rs index 738148fa..227a5abb 100644 --- a/server-manager/src/type.rs +++ b/server-manager/src/type.rs @@ -1,7 +1,7 @@ use super::*; /// Error type for server management operations. -pub type ServerManagerError = Box; +pub type ServerManagerError = Box; /// Result type for server management operations. pub type ServerManagerResult = Result<(), ServerManagerError>; diff --git a/stripe-pay-core/src/lib.rs b/stripe-pay-core/src/lib.rs index d4b242d3..ded30f84 100644 --- a/stripe-pay-core/src/lib.rs +++ b/stripe-pay-core/src/lib.rs @@ -4,8 +4,6 @@ //! handling, typed Stripe identifiers, payment intents, charges, //! refunds, structured errors, and Stripe's bracketed form encoding. -mod r#protocol; - mod charge; mod error; mod form; @@ -13,6 +11,7 @@ mod id; mod money; mod payment_intent; mod payment_method; +mod r#protocol; mod refund; pub use r#protocol::*; diff --git a/stripe-pay-core/src/protocol/const.rs b/stripe-pay-core/src/protocol/const.rs index 96e91f29..85a748af 100644 --- a/stripe-pay-core/src/protocol/const.rs +++ b/stripe-pay-core/src/protocol/const.rs @@ -116,7 +116,8 @@ pub(crate) const METADATA_VALUE_MAX_CHARS: usize = 500; pub(crate) const METADATA_KEY_LIMIT_MESSAGE: &str = "metadata key must be 1 to 40 characters"; /// Diagnostic for a metadata value outside Stripe's documented limit. -pub(crate) const METADATA_VALUE_LIMIT_MESSAGE: &str = "metadata value must be at most 500 characters"; +pub(crate) const METADATA_VALUE_LIMIT_MESSAGE: &str = + "metadata value must be at most 500 characters"; /// Byte of the hyphen form encoding passes through unescaped. pub(crate) const UNRESERVED_DASH: u8 = b'-'; diff --git a/stripe-pay-core/tests/payment/mod.rs b/stripe-pay-core/tests/payment/mod.rs index 2ae0c921..681d19a8 100644 --- a/stripe-pay-core/tests/payment/mod.rs +++ b/stripe-pay-core/tests/payment/mod.rs @@ -1,7 +1,7 @@ -use stripe_pay_core::{CardBrand, CardDetails, PaymentIntentStatus, StripeParseError}; mod r#fn; - mod method; mod transition; +use stripe_pay_core::{CardBrand, CardDetails, PaymentIntentStatus, StripeParseError}; + use super::*; diff --git a/stripe-pay-server/src/lib.rs b/stripe-pay-server/src/lib.rs index f5021d0c..38d9448e 100644 --- a/stripe-pay-server/src/lib.rs +++ b/stripe-pay-server/src/lib.rs @@ -13,3 +13,5 @@ pub use lombok_macros::*; pub use sha2::{Digest, Sha256}; pub use std::fmt::{self, Display, Formatter}; pub use stripe_pay_core::*; + +use std::env::var; diff --git a/stripe-pay-server/src/webhook/impl.rs b/stripe-pay-server/src/webhook/impl.rs index 2366aacf..e081f9ef 100644 --- a/stripe-pay-server/src/webhook/impl.rs +++ b/stripe-pay-server/src/webhook/impl.rs @@ -229,7 +229,7 @@ impl WebhookEvent { /// - `Result` - the configured secret, or /// `EmptySecret` when the variable is unset or blank. pub fn secret_from_env() -> Result { - match std::env::var(SECRET_KEY) { + match var(SECRET_KEY) { Ok(value) if !value.is_empty() => Ok(value), _ => Err(WebhookError::EmptySecret), } diff --git a/tcp-request/src/lib.rs b/tcp-request/src/lib.rs index c0113e6a..da3a8daa 100644 --- a/tcp-request/src/lib.rs +++ b/tcp-request/src/lib.rs @@ -15,8 +15,10 @@ use common::*; use lombok_macros::*; use std::{ + error::Error, fmt::Debug, fmt::{self, Display}, + io, io::{Read, Write}, net::TcpStream, sync::{Arc, PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard}, diff --git a/tcp-request/src/request/error/impl.rs b/tcp-request/src/request/error/impl.rs index b7eb0ca9..ff3584d7 100644 --- a/tcp-request/src/request/error/impl.rs +++ b/tcp-request/src/request/error/impl.rs @@ -1,7 +1,7 @@ use super::*; /// Standard error implementation for RequestError. -impl std::error::Error for RequestError {} +impl Error for RequestError {} /// Display formatting implementation for RequestError. impl Display for RequestError { diff --git a/tcp-request/src/request/tcp_request/impl.rs b/tcp-request/src/request/tcp_request/impl.rs index 161b7ce3..9334a992 100644 --- a/tcp-request/src/request/tcp_request/impl.rs +++ b/tcp-request/src/request/tcp_request/impl.rs @@ -95,13 +95,13 @@ impl TcpRequest { }); let timeout: Duration = Duration::from_millis(cfg_timeout); let tcp_stream: TcpStream = TcpStream::connect(host_port.clone()) - .map_err(|_: std::io::Error| RequestError::TcpStreamConnectError)?; + .map_err(|_: io::Error| RequestError::TcpStreamConnectError)?; tcp_stream .set_read_timeout(Some(timeout)) - .map_err(|_: std::io::Error| RequestError::SetReadTimeoutError)?; + .map_err(|_: io::Error| RequestError::SetReadTimeoutError)?; tcp_stream .set_write_timeout(Some(timeout)) - .map_err(|_: std::io::Error| RequestError::SetWriteTimeoutError)?; + .map_err(|_: io::Error| RequestError::SetWriteTimeoutError)?; let stream: Result = Ok(tcp_stream); stream } diff --git a/tcp-request/tests/mod.rs b/tcp-request/tests/mod.rs index 92a5f60e..420236fc 100644 --- a/tcp-request/tests/mod.rs +++ b/tcp-request/tests/mod.rs @@ -1,3 +1,4 @@ mod request_builder; -use tcp_request::*; \ No newline at end of file +use std::time::Duration; +use tcp_request::*; diff --git a/tcp-request/tests/request_builder/fn.rs b/tcp-request/tests/request_builder/fn.rs index 1e7c8c36..a3395237 100644 --- a/tcp-request/tests/request_builder/fn.rs +++ b/tcp-request/tests/request_builder/fn.rs @@ -41,13 +41,13 @@ fn test_thread_request() { let start_time: Instant = Instant::now(); match request_builder.send("tcp send".as_bytes()) { Ok(response) => { - let duration: std::time::Duration = start_time.elapsed(); + let duration: Duration = start_time.elapsed(); println!("{duration:?}"); let response_text = response.text(); println!("ResponseTrait => {response_text}"); } Err(e) => { - let duration: std::time::Duration = start_time.elapsed(); + let duration: Duration = start_time.elapsed(); println!("{duration:?}"); println!("Error => {e}"); } diff --git a/tcplane/src/common/const.rs b/tcplane/src/common/const.rs index 155230c1..d2803e22 100644 --- a/tcplane/src/common/const.rs +++ b/tcplane/src/common/const.rs @@ -11,7 +11,7 @@ pub const DEFAULT_BUFFER_SIZE: usize = 4096; /// Default socket address. pub const DEFAULT_SOCKET_ADDR: SocketAddr = - SocketAddr::new(std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)), 0); + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0); /// Request separator bytes for detecting end of request. pub const SPLIT_REQUEST_BYTES: &[u8] = b"\r\n\r\n"; diff --git a/tcplane/src/common/type.rs b/tcplane/src/common/type.rs index 08321a35..f5e1a2d1 100644 --- a/tcplane/src/common/type.rs +++ b/tcplane/src/common/type.rs @@ -18,7 +18,7 @@ pub type HashMapArcAnySendSync = HashMap>; pub type OptionSocketAddr = Option; /// A type alias for an optional socket host (IP address). -pub type OptionSocketHost = Option; +pub type OptionSocketHost = Option; /// A type alias for an optional socket port. pub type OptionSocketPort = Option; diff --git a/tcplane/src/context/impl.rs b/tcplane/src/context/impl.rs index c7ceb2a5..24f15af9 100644 --- a/tcplane/src/context/impl.rs +++ b/tcplane/src/context/impl.rs @@ -350,12 +350,12 @@ impl Context { /// /// # Returns /// - /// - `std::net::IpAddr` - The socket host. + /// - `IpAddr` - The socket host. /// /// # Panics /// /// Panics if the socket host is not available. - pub async fn get_socket_host(&self) -> std::net::IpAddr { + pub async fn get_socket_host(&self) -> IpAddr { self.try_get_socket_host().await.unwrap() } diff --git a/tcplane/src/error/impl.rs b/tcplane/src/error/impl.rs index 30db2dd0..f58c555b 100644 --- a/tcplane/src/error/impl.rs +++ b/tcplane/src/error/impl.rs @@ -1,7 +1,7 @@ use super::*; /// Implementation of `std::error::Error` for `ServerError`. -impl std::error::Error for ServerError {} +impl Error for ServerError {} /// Implementation of `Display` for `ServerError`. impl Display for ServerError { @@ -26,7 +26,7 @@ impl Display for ServerError { } /// Implementation of `std::error::Error` for `ResponseError`. -impl std::error::Error for ResponseError {} +impl Error for ResponseError {} /// Implementation of `Display` for `ResponseError`. impl Display for ResponseError { diff --git a/tcplane/src/lib.rs b/tcplane/src/lib.rs index 6afee729..58d31a76 100644 --- a/tcplane/src/lib.rs +++ b/tcplane/src/lib.rs @@ -28,11 +28,16 @@ pub use tokio; use std::{ any::Any, collections::HashMap, + error::Error, fmt::{self, Display}, future::Future, + io, + net::IpAddr, + net::Ipv4Addr, net::SocketAddr, pin::Pin, sync::Arc, + thread::available_parallelism, }; use { diff --git a/tcplane/src/server/impl.rs b/tcplane/src/server/impl.rs index d868c6aa..3bdd9866 100644 --- a/tcplane/src/server/impl.rs +++ b/tcplane/src/server/impl.rs @@ -165,7 +165,7 @@ impl Server { let addr: String = Self::get_bind_addr(&host, port); TcpListener::bind(&addr) .await - .map_err(|error: std::io::Error| ServerError::TcpBind(error.to_string())) + .map_err(|error: io::Error| ServerError::TcpBind(error.to_string())) } /// Spawns a new task to handle an incoming connection. diff --git a/tcplane/src/stream/impl.rs b/tcplane/src/stream/impl.rs index 0ec5e85e..1dd946d2 100644 --- a/tcplane/src/stream/impl.rs +++ b/tcplane/src/stream/impl.rs @@ -62,7 +62,7 @@ impl ArcRwLockStream { stream .write_all(data.as_ref()) .await - .map_err(|error: std::io::Error| ResponseError::WriteError(error.to_string()))?; + .map_err(|error: io::Error| ResponseError::WriteError(error.to_string()))?; Ok(()) } @@ -92,7 +92,7 @@ impl ArcRwLockStream { stream .flush() .await - .map_err(|error: std::io::Error| ResponseError::FlushError(error.to_string()))?; + .map_err(|error: io::Error| ResponseError::FlushError(error.to_string()))?; Ok(()) } @@ -138,7 +138,7 @@ impl ArcRwLockStream { stream .shutdown() .await - .map_err(|error: std::io::Error| ResponseError::WriteError(error.to_string()))?; + .map_err(|error: io::Error| ResponseError::WriteError(error.to_string()))?; Ok(()) } diff --git a/tcplane/src/utils/mod.rs b/tcplane/src/utils/mod.rs index fb69f611..76f9a77a 100644 --- a/tcplane/src/utils/mod.rs +++ b/tcplane/src/utils/mod.rs @@ -3,3 +3,5 @@ mod thread; pub use list::*; pub use thread::*; + +use super::*; diff --git a/tcplane/src/utils/thread/fn.rs b/tcplane/src/utils/thread/fn.rs index 18aefdb6..e31e077d 100644 --- a/tcplane/src/utils/thread/fn.rs +++ b/tcplane/src/utils/thread/fn.rs @@ -1,3 +1,5 @@ +use super::*; + /// Gets the number of available threads for parallel processing. /// /// This function returns the number of threads that the system can execute simultaneously, @@ -7,7 +9,7 @@ /// /// - `usize` - The number of available threads, or 1 if the value cannot be determined. pub fn get_thread_count() -> usize { - match std::thread::available_parallelism() { + match available_parallelism() { Ok(count) => count.get(), Err(_) => 1, } diff --git a/tcplane/src/utils/thread/mod.rs b/tcplane/src/utils/thread/mod.rs index 118f6803..7087a15a 100644 --- a/tcplane/src/utils/thread/mod.rs +++ b/tcplane/src/utils/thread/mod.rs @@ -1,3 +1,5 @@ mod r#fn; pub use r#fn::*; + +use super::*; diff --git a/tcplane/tests/mod.rs b/tcplane/tests/mod.rs index e7b8cf09..21600ee7 100644 --- a/tcplane/tests/mod.rs +++ b/tcplane/tests/mod.rs @@ -2,4 +2,7 @@ mod server; use tcplane::*; -use std::io::{Error, Write, stderr}; +use std::{ + io::{Error, Write, stderr}, + time::Duration, +}; diff --git a/tcplane/tests/server/fn.rs b/tcplane/tests/server/fn.rs index ea83b376..ebd7120a 100644 --- a/tcplane/tests/server/fn.rs +++ b/tcplane/tests/server/fn.rs @@ -15,7 +15,7 @@ async fn test_server_basic_usage() { let server_control_hook_1: ServerControlHook = server.run().await.unwrap_or_default(); let server_control_hook_2: ServerControlHook = server_control_hook_1.clone(); tokio::spawn(async move { - tokio::time::sleep(std::time::Duration::from_secs(60)).await; + tokio::time::sleep(Duration::from_secs(60)).await; server_control_hook_2.shutdown().await; }); server_control_hook_1.wait().await; diff --git a/tcplane/tests/server/mod.rs b/tcplane/tests/server/mod.rs index 904403cf..8a20cee3 100644 --- a/tcplane/tests/server/mod.rs +++ b/tcplane/tests/server/mod.rs @@ -2,5 +2,5 @@ mod r#fn; mod r#impl; mod r#struct; -use r#struct::*; use super::*; +use r#struct::*; diff --git a/tcplane/tests/server/struct.rs b/tcplane/tests/server/struct.rs index 366973a9..229fcda3 100644 --- a/tcplane/tests/server/struct.rs +++ b/tcplane/tests/server/struct.rs @@ -5,4 +5,4 @@ pub(crate) struct EchoHandler; #[derive(Clone, Copy, Debug)] pub(crate) struct PanicHandler; #[derive(Clone, Copy, Debug)] -pub(crate) struct ErrorHandler; \ No newline at end of file +pub(crate) struct ErrorHandler; diff --git a/udp-request/src/lib.rs b/udp-request/src/lib.rs index 6c7f67c6..197e6575 100644 --- a/udp-request/src/lib.rs +++ b/udp-request/src/lib.rs @@ -14,8 +14,10 @@ use common::*; use lombok_macros::*; use std::{ + error::Error, fmt::Debug, fmt::{self, Display}, + io, net::UdpSocket, sync::{Arc, PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard}, time::Duration, diff --git a/udp-request/src/request/error/impl.rs b/udp-request/src/request/error/impl.rs index 0cdb87eb..db26d74c 100644 --- a/udp-request/src/request/error/impl.rs +++ b/udp-request/src/request/error/impl.rs @@ -1,7 +1,7 @@ use super::*; /// Implements the `StdError` trait for `RequestError`. -impl std::error::Error for RequestError {} +impl Error for RequestError {} /// Implements the `Display` trait for `RequestError`. impl Display for RequestError { diff --git a/udp-request/src/request/udp_request/impl.rs b/udp-request/src/request/udp_request/impl.rs index dd799687..42aaa0a0 100644 --- a/udp-request/src/request/udp_request/impl.rs +++ b/udp-request/src/request/udp_request/impl.rs @@ -35,7 +35,7 @@ impl UdpRequest { ) -> Result { socket .send(data) - .map_err(|err: std::io::Error| RequestError::SendResponseError(err.to_string()))?; + .map_err(|err: io::Error| RequestError::SendResponseError(err.to_string()))?; self.read_response(socket) } @@ -89,16 +89,16 @@ impl UdpRequest { }); let timeout: Duration = Duration::from_millis(cfg_timeout); let socket: UdpSocket = UdpSocket::bind(UDP_BIND_ADDR) - .map_err(|_: std::io::Error| RequestError::UdpSocketCreateError)?; + .map_err(|_: io::Error| RequestError::UdpSocketCreateError)?; socket .connect(host_port) - .map_err(|_: std::io::Error| RequestError::UdpSocketConnectError)?; + .map_err(|_: io::Error| RequestError::UdpSocketConnectError)?; socket .set_read_timeout(Some(timeout)) - .map_err(|_: std::io::Error| RequestError::SetReadTimeoutError)?; + .map_err(|_: io::Error| RequestError::SetReadTimeoutError)?; socket .set_write_timeout(Some(timeout)) - .map_err(|_: std::io::Error| RequestError::SetWriteTimeoutError)?; + .map_err(|_: io::Error| RequestError::SetWriteTimeoutError)?; let socket_result: Result = Ok(socket); socket_result } diff --git a/udp-request/tests/mod.rs b/udp-request/tests/mod.rs index d7ee7ac9..7d4299b9 100644 --- a/udp-request/tests/mod.rs +++ b/udp-request/tests/mod.rs @@ -1,3 +1,4 @@ mod request_builder; -use udp_request::*; \ No newline at end of file +use std::time::Duration; +use udp_request::*; diff --git a/udp-request/tests/request_builder/fn.rs b/udp-request/tests/request_builder/fn.rs index 37d51b43..d1c229fc 100644 --- a/udp-request/tests/request_builder/fn.rs +++ b/udp-request/tests/request_builder/fn.rs @@ -48,13 +48,13 @@ fn test_thread_request() { let start_time: Instant = Instant::now(); match request_builder.send("test".as_bytes()) { Ok(response) => { - let duration: std::time::Duration = start_time.elapsed(); + let duration: Duration = start_time.elapsed(); println!("{duration:?}"); let response_text = response.text(); println!("ResponseTrait => {response_text}"); } Err(e) => { - let duration: std::time::Duration = start_time.elapsed(); + let duration: Duration = start_time.elapsed(); println!("{duration:?}"); println!("Error => {e}"); } diff --git a/udp/src/error/impl.rs b/udp/src/error/impl.rs index 2cbae1b4..15fb1ce9 100644 --- a/udp/src/error/impl.rs +++ b/udp/src/error/impl.rs @@ -1,7 +1,7 @@ use super::*; /// Standard error implementation for ServerError. -impl std::error::Error for ServerError {} +impl Error for ServerError {} /// Display implementation for ServerError. impl Display for ServerError { @@ -25,7 +25,7 @@ impl Display for ServerError { } /// Standard error implementation for ResponseError. -impl std::error::Error for ResponseError {} +impl Error for ResponseError {} /// Display implementation for ResponseError. impl Display for ResponseError { @@ -49,7 +49,7 @@ impl Display for ResponseError { } /// Standard error implementation for RequestError. -impl std::error::Error for RequestError {} +impl Error for RequestError {} /// Display implementation for RequestError. impl Display for RequestError { diff --git a/udp/src/lib.rs b/udp/src/lib.rs index 4a6f9e3f..74ab7a08 100644 --- a/udp/src/lib.rs +++ b/udp/src/lib.rs @@ -26,8 +26,10 @@ pub use tokio; use std::{ any::Any, collections::HashMap, + error::Error, fmt::{self, Display}, future::Future, + io, net::{IpAddr, SocketAddr}, pin::Pin, sync::Arc, diff --git a/udp/src/panic/impl.rs b/udp/src/panic/impl.rs index 6d8c7964..8dd93ea8 100644 --- a/udp/src/panic/impl.rs +++ b/udp/src/panic/impl.rs @@ -75,4 +75,4 @@ impl Display for PanicData { } /// Implementation of StdError for PanicData. -impl std::error::Error for PanicData {} +impl Error for PanicData {} diff --git a/udp/src/response/impl.rs b/udp/src/response/impl.rs index 65154f7f..2932fcfd 100644 --- a/udp/src/response/impl.rs +++ b/udp/src/response/impl.rs @@ -54,7 +54,7 @@ impl Response { socket .send_to(self.get_data(), addr) .await - .map_err(|error: std::io::Error| ResponseError::SendError(error.to_string()))?; + .map_err(|error: io::Error| ResponseError::SendError(error.to_string()))?; return Ok(()); } return Err(ResponseError::AddressNotAvailable); diff --git a/udp/src/server/impl.rs b/udp/src/server/impl.rs index 01476eca..e82178e4 100644 --- a/udp/src/server/impl.rs +++ b/udp/src/server/impl.rs @@ -179,7 +179,7 @@ impl Server { let addr: String = format!("{host}:{port}"); UdpSocket::bind(&addr) .await - .map_err(|error: std::io::Error| ServerError::UdpBind(error.to_string())) + .map_err(|error: io::Error| ServerError::UdpBind(error.to_string())) } /// Spawns a new asynchronous task to handle a single client request. diff --git a/udp/src/socket/type.rs b/udp/src/socket/type.rs index 604f5107..5fc7e444 100644 --- a/udp/src/socket/type.rs +++ b/udp/src/socket/type.rs @@ -7,7 +7,7 @@ pub type OptionArcRwLockUdpSocket = Option; pub type OptionSocketAddr = Option; /// Optional socket host IP address. -pub type OptionSocketHost = Option; +pub type OptionSocketHost = Option; /// Optional socket port number. pub type OptionSocketPort = Option; diff --git a/udp/tests/mod.rs b/udp/tests/mod.rs index 885ae442..9780fc00 100644 --- a/udp/tests/mod.rs +++ b/udp/tests/mod.rs @@ -1,3 +1,4 @@ mod server; +use std::{net::SocketAddr, time::Duration}; use udp::*; diff --git a/udp/tests/server/fn.rs b/udp/tests/server/fn.rs index 7fa846de..0041be8e 100644 --- a/udp/tests/server/fn.rs +++ b/udp/tests/server/fn.rs @@ -29,7 +29,7 @@ async fn test_context_creation() { let socket: tokio::net::UdpSocket = tokio::net::UdpSocket::bind("127.0.0.1:0").await.unwrap(); let socket: ArcRwLockUdpSocket = ArcRwLockUdpSocket::from_socket(socket); let request: Request = vec![1, 2, 3, 4]; - let client_addr: std::net::SocketAddr = std::net::SocketAddr::from(([127, 0, 0, 1], 12345)); + let client_addr: SocketAddr = SocketAddr::from(([127, 0, 0, 1], 12345)); let ctx: Context = Context::new(&socket, &request, client_addr); assert_eq!(ctx.get_request().await, request); assert_eq!(ctx.get_client_addr().await, client_addr); @@ -60,7 +60,7 @@ async fn test_server_run_and_shutdown() { let server_control_hook_1: ServerControlHook = server.run().await.unwrap_or_default(); let server_control_hook_2: ServerControlHook = server_control_hook_1.clone(); tokio::spawn(async move { - tokio::time::sleep(std::time::Duration::from_secs(60)).await; + tokio::time::sleep(Duration::from_secs(60)).await; server_control_hook_2.shutdown().await; }); server_control_hook_1.wait().await; diff --git a/udp/tests/server/mod.rs b/udp/tests/server/mod.rs index 904403cf..8a20cee3 100644 --- a/udp/tests/server/mod.rs +++ b/udp/tests/server/mod.rs @@ -2,5 +2,5 @@ mod r#fn; mod r#impl; mod r#struct; -use r#struct::*; use super::*; +use r#struct::*; diff --git a/udp/tests/server/struct.rs b/udp/tests/server/struct.rs index 6c5abe18..5fb42002 100644 --- a/udp/tests/server/struct.rs +++ b/udp/tests/server/struct.rs @@ -1,4 +1,4 @@ #[derive(Clone, Copy, Debug)] pub(crate) struct EchoHandler; #[derive(Clone, Copy, Debug)] -pub(crate) struct PanicHandler; \ No newline at end of file +pub(crate) struct PanicHandler;