From 22d2f437eb1f7ae2dbd9a214613ffe88eb11014c Mon Sep 17 00:00:00 2001 From: Oleh Martsokha Date: Tue, 18 Jun 2024 11:46:15 +0200 Subject: [PATCH] feat(all): upgrade/update deps --- Cargo.toml | 20 ++++++++--------- robotxt/Cargo.toml | 8 +++---- robotxt/build/group.rs | 2 +- robotxt/build/mod.rs | 2 +- robotxt/lib.rs | 12 +++++------ sitemapo/Cargo.toml | 8 +++---- sitemapo/build/entry.rs | 7 ++++-- sitemapo/build/index.rs | 6 ++++-- sitemapo/build/inner.rs | 2 +- sitemapo/build/plain.rs | 3 ++- sitemapo/lib.rs | 2 +- sitemapo/parse/auto.rs | 14 +++++++----- sitemapo/parse/entry.rs | 12 +++++------ sitemapo/parse/index.rs | 12 +++++------ sitemapo/parse/inner.rs | 8 +++---- sitemapo/parse/mod.rs | 14 ++++++------ sitemapo/record/entry.rs | 11 +++++----- sitemapo/record/frequency.rs | 42 +++++++++++++++++------------------- sitemapo/record/index.rs | 11 +++++----- sitemapo/record/priority.rs | 6 ++++-- 20 files changed, 106 insertions(+), 96 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2cb6861..ecb42d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,15 +14,15 @@ authors = ["Oleh Martsokha "] license = "MIT" [workspace.dependencies] -tokio = { version = "1.37.0", default-features = false } -futures-io = { version = "0.3.30", default-features = false } -futures-util = { version = "0.3.30", default-features = false } -futures-test = { version = "0.3.30", default-features = false } +tokio = { version = "1.38", default-features = false } +futures-io = { version = "0.3", default-features = false } +futures-util = { version = "0.3", default-features = false } +futures-test = { version = "0.3", default-features = false } -url = { version = "2.5.0" } -async-trait = { version = "0.1.80" } -thiserror = { version = "1.0.60" } +url = { version = "2.5" } +async-trait = { version = "0.1" } +thiserror = { version = "1.0" } -serde = { version = "1.0.201" } -serde_json = { version = "1.0.117" } -time = { version = "0.3.36", default-features = false } +serde = { version = "1.0" } +serde_json = { version = "1.0" } +time = { version = "0.3", default-features = false } diff --git a/robotxt/Cargo.toml b/robotxt/Cargo.toml index dc043b0..8338574 100644 --- a/robotxt/Cargo.toml +++ b/robotxt/Cargo.toml @@ -47,11 +47,11 @@ serde = ["dep:serde", "url/serde", "serde/derive", "serde/rc"] [dependencies] url = { workspace = true } thiserror = { workspace = true } -percent-encoding = { version = "2.3.1" } +percent-encoding = { version = "2.3" } -nom = { version = "7.1.3", optional = true } -bstr = { version = "1.9.1", optional = true } -regex = { version = "1.10.4", optional = true } +nom = { version = "7.1", optional = true } +bstr = { version = "1.9", optional = true } +regex = { version = "1.10", optional = true } serde = { workspace = true, optional = true } [dev-dependencies] diff --git a/robotxt/build/group.rs b/robotxt/build/group.rs index 737a1f7..1cdb84a 100644 --- a/robotxt/build/group.rs +++ b/robotxt/build/group.rs @@ -85,7 +85,7 @@ impl GroupBuilder { /// u.crawl_delay(5) /// }); /// ``` - pub fn crawl_delay(mut self, delay: u16) -> Self { + pub const fn crawl_delay(mut self, delay: u16) -> Self { self.delay = Some(delay); self } diff --git a/robotxt/build/mod.rs b/robotxt/build/mod.rs index faeff95..c9a8332 100644 --- a/robotxt/build/mod.rs +++ b/robotxt/build/mod.rs @@ -107,7 +107,7 @@ impl fmt::Display for RobotsBuilder { let header = self.header.as_ref().map(|h| format_comment(h)); let footer = self.footer.as_ref().map(|f| format_comment(f)); - let groups = self.groups.iter().map(|u| u.to_string()); + let groups = self.groups.iter().map(ToString::to_string); let groups = groups.collect::>().join("\n\n"); let result = [header, Some(groups), footer]; diff --git a/robotxt/lib.rs b/robotxt/lib.rs index 0d5278d..b03ba45 100644 --- a/robotxt/lib.rs +++ b/robotxt/lib.rs @@ -9,8 +9,8 @@ pub use url; #[cfg(feature = "builder")] pub use build::{GroupBuilder, RobotsBuilder}; #[cfg(feature = "parser")] -pub use parse::{AccessResult, ALL_UAS, Robots}; -pub use paths::{BYTE_LIMIT, create_url}; +pub use parse::{AccessResult, Robots, ALL_UAS}; +pub use paths::{create_url, BYTE_LIMIT}; /// Unrecoverable failure during `robots.txt` building or parsing. /// @@ -53,10 +53,10 @@ mod parse; #[doc(hidden)] pub mod prelude { - pub use super::{Error, Result}; #[cfg(feature = "builder")] - pub use super::build::{GroupBuilder, RobotsBuilder}; + pub use super::build::{GroupBuilder, RobotsBuilder}; #[cfg(feature = "parser")] - pub use super::parse::{AccessResult, ALL_UAS, Robots}; - pub use super::paths::{BYTE_LIMIT, create_url}; + pub use super::parse::{AccessResult, Robots, ALL_UAS}; + pub use super::paths::{create_url, BYTE_LIMIT}; + pub use super::{Error, Result}; } diff --git a/sitemapo/Cargo.toml b/sitemapo/Cargo.toml index 49807cc..702af36 100644 --- a/sitemapo/Cargo.toml +++ b/sitemapo/Cargo.toml @@ -42,15 +42,15 @@ extension = ["dep:isolang"] [dependencies] url = { workspace = true } thiserror = { workspace = true } -countio = { version = "0.2.17" } +countio = { version = "0.2" } -quick-xml = { version = "0.31.0" } -bytes = { version = "1.6.0", features = [] } +quick-xml = { version = "0.31" } +bytes = { version = "1.6", features = [] } time = { workspace = true, features = ["parsing", "formatting"] } tokio = { workspace = true, optional = true } async-trait = { workspace = true, optional = true } -isolang = { version = "2.4.0", optional = true, features = [] } +isolang = { version = "2.4", optional = true, features = [] } [dev-dependencies] time = { workspace = true, features = ["macros"] } diff --git a/sitemapo/build/entry.rs b/sitemapo/build/entry.rs index 46508a5..13e3fc1 100644 --- a/sitemapo/build/entry.rs +++ b/sitemapo/build/entry.rs @@ -4,7 +4,10 @@ use quick_xml::{events, Writer}; use time::format_description::well_known::Iso8601; use crate::build::{Builder, InnerBuilder, CONFIG}; -use crate::record::*; +use crate::record::{ + Entry, BYTE_LIMIT, CHANGE_FREQUENCY, LAST_MODIFIED, LOCATION, PRIORITY, RECORD_LIMIT, URL, + URL_SET, +}; use crate::{Error, Result}; /// Sitemap builder for the versatile XML file with an optional support of extensions. @@ -51,7 +54,7 @@ impl EntryBuilder { } /// Creates a new instance with the given inner parser. - pub(crate) fn from_inner(inner: InnerBuilder) -> Self { + pub(crate) const fn from_inner(inner: InnerBuilder) -> Self { Self { inner } } diff --git a/sitemapo/build/index.rs b/sitemapo/build/index.rs index 10222b1..88ab77d 100644 --- a/sitemapo/build/index.rs +++ b/sitemapo/build/index.rs @@ -4,7 +4,9 @@ use quick_xml::{events, Writer}; use time::format_description::well_known::Iso8601; use crate::build::{Builder, InnerBuilder, CONFIG}; -use crate::record::*; +use crate::record::{ + Index, BYTE_LIMIT, LAST_MODIFIED, LOCATION, RECORD_LIMIT, SITEMAP, SITEMAP_INDEX, +}; use crate::{Error, Result}; /// Sitemap index parser for the versatile XML file. @@ -51,7 +53,7 @@ impl IndexBuilder { } /// Creates a new instance with the given inner parser. - pub(crate) fn from_inner(inner: InnerBuilder) -> Self { + pub(crate) const fn from_inner(inner: InnerBuilder) -> Self { Self { inner } } diff --git a/sitemapo/build/inner.rs b/sitemapo/build/inner.rs index 42dea65..404b591 100644 --- a/sitemapo/build/inner.rs +++ b/sitemapo/build/inner.rs @@ -6,7 +6,7 @@ use time::format_description::well_known::iso8601; use crate::Error; -pub(crate) const CONFIG: iso8601::EncodedConfig = iso8601::Config::DEFAULT +pub const CONFIG: iso8601::EncodedConfig = iso8601::Config::DEFAULT .set_time_precision(iso8601::TimePrecision::Second { decimal_digits: NonZeroU8::new(2), }) diff --git a/sitemapo/build/plain.rs b/sitemapo/build/plain.rs index 1b82a75..eb6efd3 100644 --- a/sitemapo/build/plain.rs +++ b/sitemapo/build/plain.rs @@ -4,7 +4,7 @@ use countio::Counter; use url::Url; use crate::build::Builder; -use crate::record::*; +use crate::record::{BYTE_LIMIT, RECORD_LIMIT}; use crate::{Error, Result}; /// Sitemap builder for the simple TXT file that contains one URL per line. @@ -144,6 +144,7 @@ mod tokio { #[cfg(test)] mod test { use std::io::BufWriter; + use url::Url; use crate::build::{Builder, PlainBuilder}; diff --git a/sitemapo/lib.rs b/sitemapo/lib.rs index 6239cd6..89a3402 100644 --- a/sitemapo/lib.rs +++ b/sitemapo/lib.rs @@ -51,8 +51,8 @@ pub mod record; #[doc(hidden)] pub mod prelude { - pub use super::{Error, Result}; pub use super::build::*; pub use super::parse::*; pub use super::record::*; + pub use super::{Error, Result}; } diff --git a/sitemapo/parse/auto.rs b/sitemapo/parse/auto.rs index 3e3f9a2..e602fff 100644 --- a/sitemapo/parse/auto.rs +++ b/sitemapo/parse/auto.rs @@ -3,7 +3,11 @@ use countio::Counter; use quick_xml::{events, Reader}; use url::Url; -use crate::{parse::*, record::*, Error}; +use crate::{ + parse::{try_if_readable, EntryParser, IndexParser, InnerParser, Parser, PlainParser}, + record::{Entry, SITEMAP_INDEX, URL_SET}, + Error, +}; /// Sitemap type resolver. // TODO: Check for the plain txt sitemaps. @@ -147,9 +151,9 @@ impl AutoParser { /// Returns minimal (no resolved indexes) total sitemaps amount. pub fn len(&self) -> usize { self.sitemaps.len() - + self.plain.is_some() as usize - + self.index.is_some() as usize - + self.entry.is_some() as usize + + usize::from(self.plain.is_some()) + + usize::from(self.index.is_some()) + + usize::from(self.entry.is_some()) } } @@ -199,7 +203,7 @@ where if let Some(sitemap) = self.sitemaps.pop() { let reader = (fetcher)(sitemap)?; if let Ok(sitemap) = Scanner::from_sync(reader) { - self.replace_parser(sitemap) + self.replace_parser(sitemap); } } diff --git a/sitemapo/parse/entry.rs b/sitemapo/parse/entry.rs index 35ebdf3..150a695 100644 --- a/sitemapo/parse/entry.rs +++ b/sitemapo/parse/entry.rs @@ -8,7 +8,7 @@ use crate::{Error, Result}; /// [`Entry`] builder. #[derive(Debug, Clone, Default)] -pub(crate) struct EntryFactory { +pub struct EntryFactory { location: Option, modified: Option, priority: Option, @@ -78,7 +78,7 @@ impl EntryParser { } /// Creates a new instance with the given inner parser. - pub(crate) fn from_inner(inner: InnerParser) -> Self { + pub(crate) const fn from_inner(inner: InnerParser) -> Self { Self { inner } } @@ -114,17 +114,17 @@ impl EntryParser { } } - pub(crate) fn write_event(&mut self, event: events::Event) -> Result> { + pub(crate) fn write_event(&mut self, event: events::Event) -> Output { let tag = URL.as_bytes(); let builder = self.inner.write_event(event, tag, Self::apply_inner); if let Ok(Output::Some(r)) = builder { if let Some(record) = r.build() { - return Ok(Output::Some(record)); + return Output::Some(record); } } - Ok(Output::None) + Output::None } } @@ -149,7 +149,7 @@ impl Parser for EntryParser { loop { self.inner.try_if_readable()?; let event = self.inner.reader.read_event_into(&mut buf)?; - match self.write_event(event)? { + match self.write_event(event) { Output::Some(record) => return Ok(Some(record)), Output::None => {} Output::End => return Ok(None), diff --git a/sitemapo/parse/index.rs b/sitemapo/parse/index.rs index eb05574..c81b8e2 100644 --- a/sitemapo/parse/index.rs +++ b/sitemapo/parse/index.rs @@ -8,7 +8,7 @@ use crate::{Error, Result}; /// [`Index`] builder. #[derive(Debug, Clone, Default)] -pub(crate) struct IndexFactory { +pub struct IndexFactory { pub(crate) location: Option, pub(crate) modified: Option, } @@ -53,7 +53,7 @@ impl IndexParser { } /// Creates a new instance with the given inner parser. - pub(crate) fn from_inner(inner: InnerParser) -> Self { + pub(crate) const fn from_inner(inner: InnerParser) -> Self { Self { inner } } @@ -85,17 +85,17 @@ impl IndexParser { } } - pub(crate) fn write_event(&mut self, event: events::Event) -> Result> { + pub(crate) fn write_event(&mut self, event: events::Event) -> Output { let tag = SITEMAP.as_bytes(); let builder = self.inner.write_event(event, tag, Self::apply_inner); if let Ok(Output::Some(r)) = builder { if let Some(record) = r.build() { - return Ok(Output::Some(record)); + return Output::Some(record); } } - Ok(Output::None) + Output::None } } @@ -120,7 +120,7 @@ impl Parser for IndexParser { loop { self.inner.try_if_readable()?; let event = self.inner.reader.read_event_into(&mut buf)?; - match self.write_event(event)? { + match self.write_event(event) { Output::Some(record) => return Ok(Some(record)), Output::None => {} Output::End => return Ok(None), diff --git a/sitemapo/parse/inner.rs b/sitemapo/parse/inner.rs index dd0c5d0..851a59f 100644 --- a/sitemapo/parse/inner.rs +++ b/sitemapo/parse/inner.rs @@ -5,7 +5,7 @@ use quick_xml::{events::Event, Reader}; use crate::parse::try_if_readable; use crate::Result; -pub(crate) enum Output { +pub enum Output { /// Next record. Some(T), /// The event didn't result into the new record. @@ -16,11 +16,11 @@ pub(crate) enum Output { impl From> for Output { fn from(value: Option) -> Self { - value.map(Output::Some).unwrap_or(Output::End) + value.map_or(Self::End, Self::Some) } } -pub(crate) struct InnerParser { +pub struct InnerParser { pub(crate) record: Option, pub(crate) reader: Reader>, pub(crate) records: usize, @@ -113,6 +113,6 @@ impl std::fmt::Debug for InnerParser { f.debug_struct("InnerParser") .field("bytes", &self.reader.get_ref().reader_bytes()) .field("records", &self.records) - .finish() + .finish_non_exhaustive() } } diff --git a/sitemapo/parse/mod.rs b/sitemapo/parse/mod.rs index 72057b3..250e030 100644 --- a/sitemapo/parse/mod.rs +++ b/sitemapo/parse/mod.rs @@ -1,15 +1,15 @@ -mod auto; -mod entry; -mod index; -mod inner; -mod plain; - pub use auto::*; pub use entry::*; pub use index::*; pub(crate) use inner::*; pub use plain::*; +mod auto; +mod entry; +mod index; +mod inner; +mod plain; + /// Core trait for the parser implementation. pub trait Parser: Sized { type Error: std::error::Error; @@ -41,7 +41,7 @@ pub trait AsyncParser: Sized { async fn close(self) -> Result; } -pub(crate) fn try_if_readable(records: usize, bytes: usize) -> crate::Result<()> { +pub(crate) const fn try_if_readable(records: usize, bytes: usize) -> crate::Result<()> { use crate::record::{BYTE_LIMIT, RECORD_LIMIT}; if records + 1 > RECORD_LIMIT { diff --git a/sitemapo/record/entry.rs b/sitemapo/record/entry.rs index 0fb48d4..0ae6d4d 100644 --- a/sitemapo/record/entry.rs +++ b/sitemapo/record/entry.rs @@ -15,6 +15,7 @@ use crate::record::{Frequency, Priority}; /// .with_priority(Priority::MAX) /// .with_frequency(Frequency::Daily); /// ``` +#[must_use] #[derive(Debug, Clone)] pub struct Entry { pub location: Url, @@ -25,7 +26,7 @@ pub struct Entry { impl Entry { /// Creates a new instance with the given location. - pub fn new(location: Url) -> Self { + pub const fn new(location: Url) -> Self { Self { location, modified: None, @@ -35,19 +36,19 @@ impl Entry { } /// Creates a new record with the given modify timestamp. - pub fn with_modified(mut self, modified: OffsetDateTime) -> Self { + pub const fn with_modified(mut self, modified: OffsetDateTime) -> Self { self.modified = Some(modified); self } /// Creates a new record with the given priority. - pub fn with_priority(mut self, priority: Priority) -> Self { + pub const fn with_priority(mut self, priority: Priority) -> Self { self.priority = Some(priority); self } /// Creates a new record with the given change frequency. - pub fn with_frequency(mut self, frequency: Frequency) -> Self { + pub const fn with_frequency(mut self, frequency: Frequency) -> Self { self.frequency = Some(frequency); self } @@ -55,6 +56,6 @@ impl Entry { impl From for Entry { fn from(location: Url) -> Self { - Entry::new(location) + Self::new(location) } } diff --git a/sitemapo/record/frequency.rs b/sitemapo/record/frequency.rs index 649a56c..924ead2 100644 --- a/sitemapo/record/frequency.rs +++ b/sitemapo/record/frequency.rs @@ -12,6 +12,7 @@ pub struct FrequencyError; /// /// This value provides general information to search engines and /// may not correlate exactly to how often they crawl the page. +#[must_use] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Frequency { /// Describes documents that change each time they are accessed. @@ -40,17 +41,14 @@ impl Frequency { /// assert_eq!(frequency.unwrap(), Frequency::Daily); /// ``` pub fn parse(frequency: &str) -> Result { - let frequency = frequency.trim().to_lowercase(); - - use Frequency::*; - match frequency.as_str() { - "always" => Ok(Always), - "hourly" => Ok(Hourly), - "daily" => Ok(Daily), - "weekly" => Ok(Weekly), - "monthly" => Ok(Monthly), - "yearly" => Ok(Yearly), - "never" => Ok(Never), + match frequency.trim().to_lowercase().as_str() { + "always" => Ok(Self::Always), + "hourly" => Ok(Self::Hourly), + "daily" => Ok(Self::Daily), + "weekly" => Ok(Self::Weekly), + "monthly" => Ok(Self::Monthly), + "yearly" => Ok(Self::Yearly), + "never" => Ok(Self::Never), _ => Err(FrequencyError), } } @@ -66,15 +64,15 @@ impl Frequency { /// let rs = Frequency::Monthly.next_date(d0); /// assert_eq!(rs.unwrap(), datetime!(2022-10-12 12:00 UTC)) /// ``` + #[must_use] pub fn next_date(&self, date: OffsetDateTime) -> Option { - use Frequency::*; match &self { - Always | Never => None, - Hourly => Some(date + 1.hours()), - Daily => Some(date + 1.days()), - Weekly => Some(date + 7.days()), - Monthly => Some(date + 30.days()), - Yearly => Some(date + 365.days()), + Self::Always | Self::Never => None, + Self::Hourly => Some(date + 1.hours()), + Self::Daily => Some(date + 1.days()), + Self::Weekly => Some(date + 7.days()), + Self::Monthly => Some(date + 30.days()), + Self::Yearly => Some(date + 365.days()), } } @@ -88,14 +86,14 @@ impl Frequency { /// let d1 = datetime!(2022-10-12 12:00 UTC); /// assert!(Frequency::Monthly.is_outdated(d0, d1)); /// ``` + #[must_use] pub fn is_outdated(&self, date: OffsetDateTime, now: OffsetDateTime) -> bool { match &self { Self::Always => true, Self::Never => false, - _ => match self.next_date(date) { - Some(next) => next <= now, - None => unreachable!(), - }, + _ => self + .next_date(date) + .map_or_else(|| unreachable!(), |x| x <= now), } } } diff --git a/sitemapo/record/index.rs b/sitemapo/record/index.rs index 716a9ae..b54812b 100644 --- a/sitemapo/record/index.rs +++ b/sitemapo/record/index.rs @@ -11,6 +11,7 @@ use url::Url; /// let _ = Index::new(Url::parse("https://example.com/").unwrap()) /// .with_modified(datetime!(2020-01-01 0:00 UTC)); /// ``` +#[must_use] #[derive(Debug, Clone)] pub struct Index { pub location: Url, @@ -19,7 +20,7 @@ pub struct Index { impl Index { /// Creates a new record with the given location. - pub fn new(location: Url) -> Self { + pub const fn new(location: Url) -> Self { Self { location, modified: None, @@ -27,11 +28,9 @@ impl Index { } /// Creates a new record with the given modify timestamp. - pub fn with_modified(self, modified: OffsetDateTime) -> Self { - Self { - modified: Some(modified), - ..self - } + pub const fn with_modified(mut self, modified: OffsetDateTime) -> Self { + self.modified = Some(modified); + self } } diff --git a/sitemapo/record/priority.rs b/sitemapo/record/priority.rs index f0aef52..dbbd5eb 100644 --- a/sitemapo/record/priority.rs +++ b/sitemapo/record/priority.rs @@ -17,6 +17,7 @@ pub enum PriorityError { /// Valid values range from 0.0 to 1.0. This value does not affect how your /// pages are compared to pages on other sites. It only lets the search engines /// know which pages you deem most important for the crawlers. +#[must_use] #[derive(Debug, Clone, Copy, PartialEq)] pub struct Priority(f32); @@ -46,7 +47,7 @@ impl Priority { /// assert_eq!(frequency.as_inner(), 1.0); /// ``` pub fn new_fallback(priority: f32) -> Self { - Self(priority.max(0.0).min(1.0)) + Self(priority.clamp(0.0, 1.0)) } /// Tries to parse the string into the valid priority value. @@ -63,7 +64,8 @@ impl Priority { } /// Returns the internal value. - pub fn as_inner(&self) -> f32 { + #[must_use] + pub const fn as_inner(&self) -> f32 { self.0 }