apply new rustfmt.toml changes, fix some clippy lints

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-12-15 00:05:47 -05:00
parent 0317cc8cc5
commit 77e0b76408
No known key found for this signature in database
296 changed files with 7147 additions and 4300 deletions

View file

@ -66,19 +66,25 @@ impl BoolExt for bool {
}
#[inline]
fn map_ok_or<T, E, F: FnOnce() -> T>(self, err: E, f: F) -> Result<T, E> { self.ok_or(err).map(|()| f()) }
fn map_ok_or<T, E, F: FnOnce() -> T>(self, err: E, f: F) -> Result<T, E> {
self.ok_or(err).map(|()| f())
}
#[inline]
fn map_or<T, F: FnOnce() -> T>(self, err: T, f: F) -> T { self.then(f).unwrap_or(err) }
#[inline]
fn map_or_else<T, F: FnOnce() -> T>(self, err: F, f: F) -> T { self.then(f).unwrap_or_else(err) }
fn map_or_else<T, F: FnOnce() -> T>(self, err: F, f: F) -> T {
self.then(f).unwrap_or_else(err)
}
#[inline]
fn ok_or<E>(self, err: E) -> Result<(), E> { self.into_option().ok_or(err) }
#[inline]
fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<(), E> { self.into_option().ok_or_else(err) }
fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<(), E> {
self.into_option().ok_or_else(err)
}
#[inline]
fn or<T, F: FnOnce() -> T>(self, f: F) -> Option<T> { (!self).then(f) }

View file

@ -39,7 +39,9 @@ pub fn increment(old: Option<&[u8]>) -> [u8; 8] {
/// Parses 8 big-endian bytes into an u64; panic on invalid argument
#[inline]
#[must_use]
pub fn u64_from_u8(bytes: &[u8]) -> u64 { u64_from_bytes(bytes).expect("must slice at least 8 bytes") }
pub fn u64_from_u8(bytes: &[u8]) -> u64 {
u64_from_bytes(bytes).expect("must slice at least 8 bytes")
}
/// Parses the big-endian bytes into an u64.
#[inline]

View file

@ -71,13 +71,10 @@ pub fn content_disposition_type(content_type: Option<&str>) -> ContentDispositio
/// `sanitize_filename` crate
#[tracing::instrument(level = "debug")]
pub fn sanitise_filename(filename: &str) -> String {
sanitize_filename::sanitize_with_options(
filename,
sanitize_filename::Options {
truncate: false,
..Default::default()
},
)
sanitize_filename::sanitize_with_options(filename, sanitize_filename::Options {
truncate: false,
..Default::default()
})
}
/// creates the final Content-Disposition based on whether the filename exists
@ -89,11 +86,16 @@ pub fn sanitise_filename(filename: &str) -> String {
///
/// else: `Content-Disposition: attachment/inline`
pub fn make_content_disposition(
content_disposition: Option<&ContentDisposition>, content_type: Option<&str>, filename: Option<&str>,
content_disposition: Option<&ContentDisposition>,
content_type: Option<&str>,
filename: Option<&str>,
) -> ContentDisposition {
ContentDisposition::new(content_disposition_type(content_type)).with_filename(
filename
.or_else(|| content_disposition.and_then(|content_disposition| content_disposition.filename.as_deref()))
.or_else(|| {
content_disposition
.and_then(|content_disposition| content_disposition.filename.as_deref())
})
.map(sanitise_filename),
)
}
@ -102,8 +104,8 @@ pub fn make_content_disposition(
mod tests {
#[test]
fn string_sanitisation() {
const SAMPLE: &str =
"🏳this\\r\\n įs \r\\n ä \\r\nstrïng 🥴that\n\r ../../../../../../../may be\r\n malicious🏳";
const SAMPLE: &str = "🏳this\\r\\n įs \r\\n ä \\r\nstrïng 🥴that\n\r \
../../../../../../../may be\r\n malicious🏳";
const SANITISED: &str = "🏳thisrn įs n ä rstrïng 🥴that ..............may be malicious🏳";
let options = sanitize_filename::Options {
@ -125,14 +127,12 @@ mod tests {
fn empty_sanitisation() {
use crate::utils::string::EMPTY;
let result = sanitize_filename::sanitize_with_options(
EMPTY,
sanitize_filename::Options {
let result =
sanitize_filename::sanitize_with_options(EMPTY, sanitize_filename::Options {
windows: true,
truncate: true,
replacement: "",
},
);
});
assert_eq!(EMPTY, result);
}

View file

@ -31,10 +31,8 @@ impl<T: fmt::Debug> fmt::Debug for TruncatedSlice<'_, T> {
/// fn bar(foos: &[&str]);
/// ```
pub fn slice_truncated<T: fmt::Debug>(
slice: &[T], max_len: usize,
slice: &[T],
max_len: usize,
) -> tracing::field::DebugValue<TruncatedSlice<'_, T>> {
tracing::field::debug(TruncatedSlice {
inner: slice,
max_len,
})
tracing::field::debug(TruncatedSlice { inner: slice, max_len })
}

View file

@ -9,9 +9,7 @@ macro_rules! defer {
fn drop(&mut self) { (self.closure)(); }
}
let _defer_ = _Defer_ {
closure: || $body,
};
let _defer_ = _Defer_ { closure: || $body };
};
($body:expr) => {

View file

@ -14,17 +14,23 @@ pub trait TryExtExt<T, E>
where
Self: TryFuture<Ok = T, Error = E> + Send,
{
fn is_err(self) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
fn is_err(
self,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
where
Self: Sized;
#[allow(clippy::wrong_self_convention)]
fn is_ok(self) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
fn is_ok(
self,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
where
Self: Sized;
fn map_ok_or<U, F>(
self, default: U, f: F,
self,
default: U,
f: F,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> U, impl FnOnce(Self::Error) -> U>
where
F: FnOnce(Self::Ok) -> U,
@ -32,11 +38,18 @@ where
fn ok(
self,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> Option<Self::Ok>, impl FnOnce(Self::Error) -> Option<Self::Ok>>
) -> MapOkOrElse<
Self,
impl FnOnce(Self::Ok) -> Option<Self::Ok>,
impl FnOnce(Self::Error) -> Option<Self::Ok>,
>
where
Self: Sized;
fn unwrap_or(self, default: Self::Ok) -> UnwrapOrElse<Self, impl FnOnce(Self::Error) -> Self::Ok>
fn unwrap_or(
self,
default: Self::Ok,
) -> UnwrapOrElse<Self, impl FnOnce(Self::Error) -> Self::Ok>
where
Self: Sized;
@ -51,7 +64,9 @@ where
Fut: TryFuture<Ok = T, Error = E> + Send,
{
#[inline]
fn is_err(self) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
fn is_err(
self,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
where
Self: Sized,
{
@ -59,7 +74,9 @@ where
}
#[inline]
fn is_ok(self) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
fn is_ok(
self,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> bool, impl FnOnce(Self::Error) -> bool>
where
Self: Sized,
{
@ -68,7 +85,9 @@ where
#[inline]
fn map_ok_or<U, F>(
self, default: U, f: F,
self,
default: U,
f: F,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> U, impl FnOnce(Self::Error) -> U>
where
F: FnOnce(Self::Ok) -> U,
@ -80,7 +99,11 @@ where
#[inline]
fn ok(
self,
) -> MapOkOrElse<Self, impl FnOnce(Self::Ok) -> Option<Self::Ok>, impl FnOnce(Self::Error) -> Option<Self::Ok>>
) -> MapOkOrElse<
Self,
impl FnOnce(Self::Ok) -> Option<Self::Ok>,
impl FnOnce(Self::Error) -> Option<Self::Ok>,
>
where
Self: Sized,
{
@ -88,7 +111,10 @@ where
}
#[inline]
fn unwrap_or(self, default: Self::Ok) -> UnwrapOrElse<Self, impl FnOnce(Self::Error) -> Self::Ok>
fn unwrap_or(
self,
default: Self::Ok,
) -> UnwrapOrElse<Self, impl FnOnce(Self::Error) -> Self::Ok>
where
Self: Sized,
{

View file

@ -1,8 +1,8 @@
use std::sync::OnceLock;
use argon2::{
password_hash, password_hash::SaltString, Algorithm, Argon2, Params, PasswordHash, PasswordHasher,
PasswordVerifier, Version,
password_hash, password_hash::SaltString, Algorithm, Argon2, Params, PasswordHash,
PasswordHasher, PasswordVerifier, Version,
};
use crate::{err, Error, Result};

View file

@ -16,12 +16,12 @@ impl fmt::Display for Escape<'_> {
let mut last = 0;
for (i, ch) in s.char_indices() {
let s = match ch {
'>' => "&gt;",
'<' => "&lt;",
'&' => "&amp;",
'\'' => "&#39;",
'"' => "&quot;",
_ => continue,
| '>' => "&gt;",
| '<' => "&lt;",
| '&' => "&amp;",
| '\'' => "&#39;",
| '"' => "&quot;",
| _ => continue,
};
fmt.write_str(&pile_o_bits[last..i])?;
fmt.write_str(s)?;

View file

@ -8,16 +8,24 @@ use crate::Result;
/// `CanonicalJsonObject`.
///
/// `value` must serialize to an `serde_json::Value::Object`.
pub fn to_canonical_object<T: serde::Serialize>(value: T) -> Result<CanonicalJsonObject, CanonicalJsonError> {
pub fn to_canonical_object<T: serde::Serialize>(
value: T,
) -> Result<CanonicalJsonObject, CanonicalJsonError> {
use serde::ser::Error;
match serde_json::to_value(value).map_err(CanonicalJsonError::SerDe)? {
serde_json::Value::Object(map) => try_from_json_map(map),
_ => Err(CanonicalJsonError::SerDe(serde_json::Error::custom("Value must be an object"))),
| serde_json::Value::Object(map) => try_from_json_map(map),
| _ =>
Err(CanonicalJsonError::SerDe(serde_json::Error::custom("Value must be an object"))),
}
}
pub fn deserialize_from_str<'de, D: serde::de::Deserializer<'de>, T: FromStr<Err = E>, E: fmt::Display>(
pub fn deserialize_from_str<
'de,
D: serde::de::Deserializer<'de>,
T: FromStr<Err = E>,
E: fmt::Display,
>(
deserializer: D,
) -> Result<T, D::Error> {
struct Visitor<T: FromStr<Err = E>, E>(std::marker::PhantomData<T>);

View file

@ -56,7 +56,12 @@ macro_rules! validated {
/// Returns false if the exponential backoff has expired based on the inputs
#[inline]
#[must_use]
pub fn continue_exponential_backoff_secs(min: u64, max: u64, elapsed: Duration, tries: u32) -> bool {
pub fn continue_exponential_backoff_secs(
min: u64,
max: u64,
elapsed: Duration,
tries: u32,
) -> bool {
let min = Duration::from_secs(min);
let max = Duration::from_secs(max);
continue_exponential_backoff(min, max, elapsed, tries)
@ -65,7 +70,12 @@ pub fn continue_exponential_backoff_secs(min: u64, max: u64, elapsed: Duration,
/// Returns false if the exponential backoff has expired based on the inputs
#[inline]
#[must_use]
pub fn continue_exponential_backoff(min: Duration, max: Duration, elapsed: Duration, tries: u32) -> bool {
pub fn continue_exponential_backoff(
min: Duration,
max: Duration,
elapsed: Duration,
tries: u32,
) -> bool {
let min = min.saturating_mul(tries).saturating_mul(tries);
let min = cmp::min(min, max);
elapsed < min

View file

@ -47,8 +47,8 @@ pub fn exchange<T>(state: &mut T, source: T) -> T { std::mem::replace(state, sou
macro_rules! extract_variant {
($e:expr, $variant:path) => {
match $e {
$variant(value) => Some(value),
_ => None,
| $variant(value) => Some(value),
| _ => None,
}
};
}

View file

@ -70,10 +70,9 @@ where
impl<Key, Val> Drop for Guard<Key, Val> {
fn drop(&mut self) {
if Arc::strong_count(Omg::mutex(&self.val)) <= 2 {
self.map
.lock()
.expect("locked")
.retain(|_, val| !Arc::ptr_eq(val, Omg::mutex(&self.val)) || Arc::strong_count(val) > 2);
self.map.lock().expect("locked").retain(|_, val| {
!Arc::ptr_eq(val, Omg::mutex(&self.val)) || Arc::strong_count(val) > 2
});
}
}
}

View file

@ -10,9 +10,9 @@ mod unwrap_infallible;
mod unwrap_or_err;
pub use self::{
debug_inspect::DebugInspect, filter::Filter, flat_ok::FlatOk, into_is_ok::IntoIsOk, log_debug_err::LogDebugErr,
log_err::LogErr, map_expect::MapExpect, not_found::NotFound, unwrap_infallible::UnwrapInfallible,
unwrap_or_err::UnwrapOrErr,
debug_inspect::DebugInspect, filter::Filter, flat_ok::FlatOk, into_is_ok::IntoIsOk,
log_debug_err::LogDebugErr, log_err::LogErr, map_expect::MapExpect, not_found::NotFound,
unwrap_infallible::UnwrapInfallible, unwrap_or_err::UnwrapOrErr,
};
pub type Result<T = (), E = crate::Error> = std::result::Result<T, E>;

View file

@ -19,7 +19,9 @@ impl<T, E> FlatOk<T> for Option<Result<T, E>> {
fn flat_ok_or<Ep>(self, err: Ep) -> Result<T, Ep> { self.flat_ok().ok_or(err) }
#[inline]
fn flat_ok_or_else<Ep, F: FnOnce() -> Ep>(self, err: F) -> Result<T, Ep> { self.flat_ok().ok_or_else(err) }
fn flat_ok_or_else<Ep, F: FnOnce() -> Ep>(self, err: F) -> Result<T, Ep> {
self.flat_ok().ok_or_else(err)
}
}
impl<T, E> FlatOk<T> for Result<Option<T>, E> {
@ -30,5 +32,7 @@ impl<T, E> FlatOk<T> for Result<Option<T>, E> {
fn flat_ok_or<Ep>(self, err: Ep) -> Result<T, Ep> { self.flat_ok().ok_or(err) }
#[inline]
fn flat_ok_or_else<Ep, F: FnOnce() -> Ep>(self, err: F) -> Result<T, Ep> { self.flat_ok().ok_or_else(err) }
fn flat_ok_or_else<Ep, F: FnOnce() -> Ep>(self, err: F) -> Result<T, Ep> {
self.flat_ok().ok_or_else(err)
}
}

View file

@ -20,5 +20,7 @@ pub trait LogErr<T, E: Display> {
impl<T, E: Display> LogErr<T, E> for Result<T, E> {
#[inline]
fn err_log(self, level: Level) -> Self { self.inspect_err(|error| error::inspect_log_level(&error, level)) }
fn err_log(self, level: Level) -> Self {
self.inspect_err(|error| error::inspect_log_level(&error, level))
}
}

View file

@ -32,7 +32,9 @@ where
/// Intersection of sets
///
/// Outputs the set of elements common to all input sets. Inputs must be sorted.
pub fn intersection_sorted<Item, Iter, Iters>(mut input: Iters) -> impl Iterator<Item = Item> + Send
pub fn intersection_sorted<Item, Iter, Iters>(
mut input: Iters,
) -> impl Iterator<Item = Item> + Send
where
Iters: Iterator<Item = Iter> + Clone + Send,
Iter: Iterator<Item = Item> + Send,

View file

@ -14,9 +14,13 @@ where
Item: 'a,
{
#[inline]
fn expect_ok(self: T) -> impl Stream<Item = Item> + Send + 'a { self.map_expect("stream expectation failure") }
fn expect_ok(self: T) -> impl Stream<Item = Item> + Send + 'a {
self.map_expect("stream expectation failure")
}
//TODO: move to impl MapExpect
#[inline]
fn map_expect(self, msg: &'a str) -> impl Stream<Item = Item> + Send + 'a { self.map(|res| res.expect(msg)) }
fn map_expect(self, msg: &'a str) -> impl Stream<Item = Item> + Send + 'a {
self.map(|res| res.expect(msg))
}
}

View file

@ -23,8 +23,12 @@ where
#[cfg(not(debug_assertions))]
#[inline]
fn ignore_err(self: T) -> impl Stream<Item = Item> + Send + 'a { self.filter_map(|res| ready(res.ok())) }
fn ignore_err(self: T) -> impl Stream<Item = Item> + Send + 'a {
self.filter_map(|res| ready(res.ok()))
}
#[inline]
fn ignore_ok(self: T) -> impl Stream<Item = Error> + Send + 'a { self.filter_map(|res| ready(res.err())) }
fn ignore_ok(self: T) -> impl Stream<Item = Error> + Send + 'a {
self.filter_map(|res| ready(res.err()))
}
}

View file

@ -13,7 +13,11 @@ pub trait IterStream<I: IntoIterator + Send> {
/// Convert an Iterator into a TryStream
fn try_stream(
self,
) -> impl TryStream<Ok = <I as IntoIterator>::Item, Error = Error, Item = Result<<I as IntoIterator>::Item, Error>> + Send;
) -> impl TryStream<
Ok = <I as IntoIterator>::Item,
Error = Error,
Item = Result<<I as IntoIterator>::Item, Error>,
> + Send;
}
impl<I> IterStream<I> for I
@ -27,8 +31,11 @@ where
#[inline]
fn try_stream(
self,
) -> impl TryStream<Ok = <I as IntoIterator>::Item, Error = Error, Item = Result<<I as IntoIterator>::Item, Error>> + Send
{
) -> impl TryStream<
Ok = <I as IntoIterator>::Item,
Error = Error,
Item = Result<<I as IntoIterator>::Item, Error>,
> + Send {
self.stream().map(Ok)
}
}

View file

@ -3,7 +3,9 @@
use futures::{
future::{ready, Ready},
stream::{All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile},
stream::{
All, Any, Filter, FilterMap, Fold, ForEach, Scan, SkipWhile, Stream, StreamExt, TakeWhile,
},
};
/// Synchronous combinators to augment futures::StreamExt. Most Stream
@ -24,19 +26,32 @@ where
where
F: Fn(Item) -> bool;
fn ready_filter<'a, F>(self, f: F) -> Filter<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
fn ready_filter<'a, F>(
self,
f: F,
) -> Filter<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
where
F: Fn(&Item) -> bool + 'a;
fn ready_filter_map<F, U>(self, f: F) -> FilterMap<Self, Ready<Option<U>>, impl FnMut(Item) -> Ready<Option<U>>>
fn ready_filter_map<F, U>(
self,
f: F,
) -> FilterMap<Self, Ready<Option<U>>, impl FnMut(Item) -> Ready<Option<U>>>
where
F: Fn(Item) -> Option<U>;
fn ready_fold<T, F>(self, init: T, f: F) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
fn ready_fold<T, F>(
self,
init: T,
f: F,
) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
where
F: Fn(T, Item) -> T;
fn ready_fold_default<T, F>(self, f: F) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
fn ready_fold_default<T, F>(
self,
f: F,
) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
where
F: Fn(T, Item) -> T,
T: Default;
@ -45,23 +60,33 @@ where
where
F: FnMut(Item);
fn ready_take_while<'a, F>(self, f: F) -> TakeWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
fn ready_take_while<'a, F>(
self,
f: F,
) -> TakeWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
where
F: Fn(&Item) -> bool + 'a;
fn ready_scan<B, T, F>(
self, init: T, f: F,
self,
init: T,
f: F,
) -> Scan<Self, T, Ready<Option<B>>, impl FnMut(&mut T, Item) -> Ready<Option<B>>>
where
F: Fn(&mut T, Item) -> Option<B>;
fn ready_scan_each<T, F>(
self, init: T, f: F,
self,
init: T,
f: F,
) -> Scan<Self, T, Ready<Option<Item>>, impl FnMut(&mut T, Item) -> Ready<Option<Item>>>
where
F: Fn(&mut T, &Item);
fn ready_skip_while<'a, F>(self, f: F) -> SkipWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
fn ready_skip_while<'a, F>(
self,
f: F,
) -> SkipWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
where
F: Fn(&Item) -> bool + 'a;
}
@ -87,7 +112,10 @@ where
}
#[inline]
fn ready_filter<'a, F>(self, f: F) -> Filter<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
fn ready_filter<'a, F>(
self,
f: F,
) -> Filter<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
where
F: Fn(&Item) -> bool + 'a,
{
@ -95,7 +123,10 @@ where
}
#[inline]
fn ready_filter_map<F, U>(self, f: F) -> FilterMap<Self, Ready<Option<U>>, impl FnMut(Item) -> Ready<Option<U>>>
fn ready_filter_map<F, U>(
self,
f: F,
) -> FilterMap<Self, Ready<Option<U>>, impl FnMut(Item) -> Ready<Option<U>>>
where
F: Fn(Item) -> Option<U>,
{
@ -103,7 +134,11 @@ where
}
#[inline]
fn ready_fold<T, F>(self, init: T, f: F) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
fn ready_fold<T, F>(
self,
init: T,
f: F,
) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
where
F: Fn(T, Item) -> T,
{
@ -111,7 +146,10 @@ where
}
#[inline]
fn ready_fold_default<T, F>(self, f: F) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
fn ready_fold_default<T, F>(
self,
f: F,
) -> Fold<Self, Ready<T>, T, impl FnMut(T, Item) -> Ready<T>>
where
F: Fn(T, Item) -> T,
T: Default,
@ -121,7 +159,10 @@ where
#[inline]
#[allow(clippy::unit_arg)]
fn ready_for_each<F>(self, mut f: F) -> ForEach<Self, Ready<()>, impl FnMut(Item) -> Ready<()>>
fn ready_for_each<F>(
self,
mut f: F,
) -> ForEach<Self, Ready<()>, impl FnMut(Item) -> Ready<()>>
where
F: FnMut(Item),
{
@ -129,7 +170,10 @@ where
}
#[inline]
fn ready_take_while<'a, F>(self, f: F) -> TakeWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
fn ready_take_while<'a, F>(
self,
f: F,
) -> TakeWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
where
F: Fn(&Item) -> bool + 'a,
{
@ -138,7 +182,9 @@ where
#[inline]
fn ready_scan<B, T, F>(
self, init: T, f: F,
self,
init: T,
f: F,
) -> Scan<Self, T, Ready<Option<B>>, impl FnMut(&mut T, Item) -> Ready<Option<B>>>
where
F: Fn(&mut T, Item) -> Option<B>,
@ -148,7 +194,9 @@ where
#[inline]
fn ready_scan_each<T, F>(
self, init: T, f: F,
self,
init: T,
f: F,
) -> Scan<Self, T, Ready<Option<Item>>, impl FnMut(&mut T, Item) -> Ready<Option<Item>>>
where
F: Fn(&mut T, &Item),
@ -160,7 +208,10 @@ where
}
#[inline]
fn ready_skip_while<'a, F>(self, f: F) -> SkipWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
fn ready_skip_while<'a, F>(
self,
f: F,
) -> SkipWhile<Self, Ready<bool>, impl FnMut(&Item) -> Ready<bool> + 'a>
where
F: Fn(&Item) -> bool + 'a,
{

View file

@ -24,12 +24,17 @@ where
F: Fn(Item) -> K + Send,
K: Eq + Hash + Send;
fn counts_by_with_cap<const CAP: usize, K, F>(self, f: F) -> impl Future<Output = HashMap<K, usize>> + Send
fn counts_by_with_cap<const CAP: usize, K, F>(
self,
f: F,
) -> impl Future<Output = HashMap<K, usize>> + Send
where
F: Fn(Item) -> K + Send,
K: Eq + Hash + Send;
fn counts_with_cap<const CAP: usize>(self) -> impl Future<Output = HashMap<Item, usize>> + Send
fn counts_with_cap<const CAP: usize>(
self,
) -> impl Future<Output = HashMap<Item, usize>> + Send
where
<Self as Stream>::Item: Eq + Hash;
@ -63,7 +68,10 @@ where
}
#[inline]
fn counts_by_with_cap<const CAP: usize, K, F>(self, f: F) -> impl Future<Output = HashMap<K, usize>> + Send
fn counts_by_with_cap<const CAP: usize, K, F>(
self,
f: F,
) -> impl Future<Output = HashMap<K, usize>> + Send
where
F: Fn(Item) -> K + Send,
K: Eq + Hash + Send,
@ -72,7 +80,9 @@ where
}
#[inline]
fn counts_with_cap<const CAP: usize>(self) -> impl Future<Output = HashMap<Item, usize>> + Send
fn counts_with_cap<const CAP: usize>(
self,
) -> impl Future<Output = HashMap<Item, usize>> + Send
where
<Self as Stream>::Item: Eq + Hash,
{

View file

@ -12,13 +12,20 @@ pub trait TryBroadbandExt<T, E>
where
Self: TryStream<Ok = T, Error = E, Item = Result<T, E>> + Send + Sized,
{
fn broadn_and_then<U, F, Fut, N>(self, n: N, f: F) -> impl TryStream<Ok = U, Error = E, Item = Result<U, E>> + Send
fn broadn_and_then<U, F, Fut, N>(
self,
n: N,
f: F,
) -> impl TryStream<Ok = U, Error = E, Item = Result<U, E>> + Send
where
N: Into<Option<usize>>,
F: Fn(Self::Ok) -> Fut + Send + Sync,
Fut: TryFuture<Ok = U, Error = E, Output = Result<U, E>> + Send;
fn broad_and_then<U, F, Fut>(self, f: F) -> impl TryStream<Ok = U, Error = E, Item = Result<U, E>> + Send
fn broad_and_then<U, F, Fut>(
self,
f: F,
) -> impl TryStream<Ok = U, Error = E, Item = Result<U, E>> + Send
where
F: Fn(Self::Ok) -> Fut + Send + Sync,
Fut: TryFuture<Ok = U, Error = E, Output = Result<U, E>> + Send,
@ -31,7 +38,11 @@ impl<T, E, S> TryBroadbandExt<T, E> for S
where
S: TryStream<Ok = T, Error = E, Item = Result<T, E>> + Send + Sized,
{
fn broadn_and_then<U, F, Fut, N>(self, n: N, f: F) -> impl TryStream<Ok = U, Error = E, Item = Result<U, E>> + Send
fn broadn_and_then<U, F, Fut, N>(
self,
n: N,
f: F,
) -> impl TryStream<Ok = U, Error = E, Item = Result<U, E>> + Send
where
N: Into<Option<usize>>,
F: Fn(Self::Ok) -> Fut + Send + Sync,

View file

@ -16,31 +16,43 @@ where
S: TryStream<Ok = T, Error = E, Item = Result<T, E>> + Send + ?Sized,
Self: TryStream + Send + Sized,
{
fn ready_and_then<U, F>(self, f: F) -> AndThen<Self, Ready<Result<U, E>>, impl FnMut(S::Ok) -> Ready<Result<U, E>>>
fn ready_and_then<U, F>(
self,
f: F,
) -> AndThen<Self, Ready<Result<U, E>>, impl FnMut(S::Ok) -> Ready<Result<U, E>>>
where
F: Fn(S::Ok) -> Result<U, E>;
fn ready_try_filter_map<F, U>(
self, f: F,
) -> TryFilterMap<Self, Ready<Result<Option<U>, E>>, impl FnMut(S::Ok) -> Ready<Result<Option<U>, E>>>
self,
f: F,
) -> TryFilterMap<
Self,
Ready<Result<Option<U>, E>>,
impl FnMut(S::Ok) -> Ready<Result<Option<U>, E>>,
>
where
F: Fn(S::Ok) -> Result<Option<U>, E>;
fn ready_try_fold<U, F>(
self, init: U, f: F,
self,
init: U,
f: F,
) -> TryFold<Self, Ready<Result<U, E>>, U, impl FnMut(U, S::Ok) -> Ready<Result<U, E>>>
where
F: Fn(U, S::Ok) -> Result<U, E>;
fn ready_try_fold_default<U, F>(
self, f: F,
self,
f: F,
) -> TryFold<Self, Ready<Result<U, E>>, U, impl FnMut(U, S::Ok) -> Ready<Result<U, E>>>
where
F: Fn(U, S::Ok) -> Result<U, E>,
U: Default;
fn ready_try_for_each<F>(
self, f: F,
self,
f: F,
) -> TryForEach<Self, Ready<Result<(), E>>, impl FnMut(S::Ok) -> Ready<Result<(), E>>>
where
F: FnMut(S::Ok) -> Result<(), E>;
@ -52,7 +64,10 @@ where
Self: TryStream + Send + Sized,
{
#[inline]
fn ready_and_then<U, F>(self, f: F) -> AndThen<Self, Ready<Result<U, E>>, impl FnMut(S::Ok) -> Ready<Result<U, E>>>
fn ready_and_then<U, F>(
self,
f: F,
) -> AndThen<Self, Ready<Result<U, E>>, impl FnMut(S::Ok) -> Ready<Result<U, E>>>
where
F: Fn(S::Ok) -> Result<U, E>,
{
@ -60,8 +75,13 @@ where
}
fn ready_try_filter_map<F, U>(
self, f: F,
) -> TryFilterMap<Self, Ready<Result<Option<U>, E>>, impl FnMut(S::Ok) -> Ready<Result<Option<U>, E>>>
self,
f: F,
) -> TryFilterMap<
Self,
Ready<Result<Option<U>, E>>,
impl FnMut(S::Ok) -> Ready<Result<Option<U>, E>>,
>
where
F: Fn(S::Ok) -> Result<Option<U>, E>,
{
@ -70,7 +90,9 @@ where
#[inline]
fn ready_try_fold<U, F>(
self, init: U, f: F,
self,
init: U,
f: F,
) -> TryFold<Self, Ready<Result<U, E>>, U, impl FnMut(U, S::Ok) -> Ready<Result<U, E>>>
where
F: Fn(U, S::Ok) -> Result<U, E>,
@ -80,7 +102,8 @@ where
#[inline]
fn ready_try_fold_default<U, F>(
self, f: F,
self,
f: F,
) -> TryFold<Self, Ready<Result<U, E>>, U, impl FnMut(U, S::Ok) -> Ready<Result<U, E>>>
where
F: Fn(U, S::Ok) -> Result<U, E>,
@ -91,7 +114,8 @@ where
#[inline]
fn ready_try_for_each<F>(
self, mut f: F,
self,
mut f: F,
) -> TryForEach<Self, Ready<Result<(), E>>, impl FnMut(S::Ok) -> Ready<Result<(), E>>>
where
F: FnMut(S::Ok) -> Result<(), E>,

View file

@ -15,7 +15,9 @@ pub trait Between<'a> {
impl<'a> Between<'a> for &'a str {
#[inline]
fn between_infallible(&self, delim: Delim<'_>) -> &'a str { self.between(delim).unwrap_or(self) }
fn between_infallible(&self, delim: Delim<'_>) -> &'a str {
self.between(delim).unwrap_or(self)
}
#[inline]
fn between(&self, delim: Delim<'_>) -> Option<&'a str> {

View file

@ -15,8 +15,12 @@ pub trait SplitInfallible<'a> {
impl<'a> SplitInfallible<'a> for &'a str {
#[inline]
fn rsplit_once_infallible(&self, delim: &str) -> Pair<'a> { self.rsplit_once(delim).unwrap_or((self, EMPTY)) }
fn rsplit_once_infallible(&self, delim: &str) -> Pair<'a> {
self.rsplit_once(delim).unwrap_or((self, EMPTY))
}
#[inline]
fn split_once_infallible(&self, delim: &str) -> Pair<'a> { self.split_once(delim).unwrap_or((self, EMPTY)) }
fn split_once_infallible(&self, delim: &str) -> Pair<'a> {
self.split_once(delim).unwrap_or((self, EMPTY))
}
}

View file

@ -26,7 +26,9 @@ impl<'a> Unquote<'a> for &'a str {
}
#[inline]
fn unquote(&self) -> Option<&'a str> { self.strip_prefix(QUOTE).and_then(|s| s.strip_suffix(QUOTE)) }
fn unquote(&self) -> Option<&'a str> {
self.strip_prefix(QUOTE).and_then(|s| s.strip_suffix(QUOTE))
}
#[inline]
fn is_quoted(&self) -> bool { self.starts_with(QUOTE) && self.ends_with(QUOTE) }

View file

@ -45,8 +45,8 @@ pub unsafe fn current_exe() -> Result<std::path::PathBuf> {
let exe = std::env::current_exe()?;
match exe.to_str() {
None => Ok(exe),
Some(str) => Ok(str
| None => Ok(exe),
| Some(str) => Ok(str
.strip_suffix(" (deleted)")
.map(PathBuf::from)
.unwrap_or(exe)),
@ -58,5 +58,6 @@ pub unsafe fn current_exe() -> Result<std::path::PathBuf> {
/// accurate on all platforms; defaults to false.
#[must_use]
pub fn current_exe_deleted() -> bool {
std::env::current_exe().is_ok_and(|exe| exe.to_str().is_some_and(|exe| exe.ends_with(" (deleted)")))
std::env::current_exe()
.is_ok_and(|exe| exe.to_str().is_some_and(|exe| exe.ends_with(" (deleted)")))
}

View file

@ -1,4 +1,5 @@
#![cfg(test)]
#![allow(clippy::disallowed_methods)]
use crate::utils;

View file

@ -13,7 +13,9 @@ pub fn now_millis() -> u64 {
}
#[inline]
pub fn parse_timepoint_ago(ago: &str) -> Result<SystemTime> { timepoint_ago(parse_duration(ago)?) }
pub fn parse_timepoint_ago(ago: &str) -> Result<SystemTime> {
timepoint_ago(parse_duration(ago)?)
}
#[inline]
pub fn timepoint_ago(duration: Duration) -> Result<SystemTime> {
@ -61,13 +63,13 @@ pub fn pretty(d: Duration) -> String {
let gen64 = |w, f, u| fmt(w, (f * 100.0) as u32, u);
let gen128 = |w, f, u| gen64(u64::try_from(w).expect("u128 to u64"), f, u);
match whole_and_frac(d) {
(Days(whole), frac) => gen64(whole, frac, "days"),
(Hours(whole), frac) => gen64(whole, frac, "hours"),
(Mins(whole), frac) => gen64(whole, frac, "minutes"),
(Secs(whole), frac) => gen64(whole, frac, "seconds"),
(Millis(whole), frac) => gen128(whole, frac, "milliseconds"),
(Micros(whole), frac) => gen128(whole, frac, "microseconds"),
(Nanos(whole), frac) => gen128(whole, frac, "nanoseconds"),
| (Days(whole), frac) => gen64(whole, frac, "days"),
| (Hours(whole), frac) => gen64(whole, frac, "hours"),
| (Mins(whole), frac) => gen64(whole, frac, "minutes"),
| (Secs(whole), frac) => gen64(whole, frac, "seconds"),
| (Millis(whole), frac) => gen128(whole, frac, "milliseconds"),
| (Micros(whole), frac) => gen128(whole, frac, "microseconds"),
| (Nanos(whole), frac) => gen128(whole, frac, "nanoseconds"),
}
}
@ -80,18 +82,15 @@ pub fn whole_and_frac(d: Duration) -> (Unit, f64) {
use Unit::*;
let whole = whole_unit(d);
(
whole,
match whole {
Days(_) => (d.as_secs() % 86_400) as f64 / 86_400.0,
Hours(_) => (d.as_secs() % 3_600) as f64 / 3_600.0,
Mins(_) => (d.as_secs() % 60) as f64 / 60.0,
Secs(_) => f64::from(d.subsec_millis()) / 1000.0,
Millis(_) => f64::from(d.subsec_micros()) / 1000.0,
Micros(_) => f64::from(d.subsec_nanos()) / 1000.0,
Nanos(_) => 0.0,
},
)
(whole, match whole {
| Days(_) => (d.as_secs() % 86_400) as f64 / 86_400.0,
| Hours(_) => (d.as_secs() % 3_600) as f64 / 3_600.0,
| Mins(_) => (d.as_secs() % 60) as f64 / 60.0,
| Secs(_) => f64::from(d.subsec_millis()) / 1000.0,
| Millis(_) => f64::from(d.subsec_micros()) / 1000.0,
| Micros(_) => f64::from(d.subsec_nanos()) / 1000.0,
| Nanos(_) => 0.0,
})
}
/// Return the largest Unit which represents the duration. The value is
@ -101,18 +100,18 @@ pub fn whole_unit(d: Duration) -> Unit {
use Unit::*;
match d.as_secs() {
86_400.. => Days(d.as_secs() / 86_400),
3_600..=86_399 => Hours(d.as_secs() / 3_600),
60..=3_599 => Mins(d.as_secs() / 60),
| 86_400.. => Days(d.as_secs() / 86_400),
| 3_600..=86_399 => Hours(d.as_secs() / 3_600),
| 60..=3_599 => Mins(d.as_secs() / 60),
_ => match d.as_micros() {
1_000_000.. => Secs(d.as_secs()),
1_000..=999_999 => Millis(d.subsec_millis().into()),
| _ => match d.as_micros() {
| 1_000_000.. => Secs(d.as_secs()),
| 1_000..=999_999 => Millis(d.subsec_millis().into()),
_ => match d.as_nanos() {
1_000.. => Micros(d.subsec_micros().into()),
| _ => match d.as_nanos() {
| 1_000.. => Micros(d.subsec_micros().into()),
_ => Nanos(d.subsec_nanos().into()),
| _ => Nanos(d.subsec_nanos().into()),
},
},
}