Remove unused utils.
Co-authored-by: dasha_uwu <dasha@linuxping.win> Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
use super::{Count, RawId};
|
use super::{Count, RawId};
|
||||||
use crate::utils::u64_from_u8x8;
|
|
||||||
|
|
||||||
pub type ShortRoomId = ShortId;
|
pub type ShortRoomId = ShortId;
|
||||||
pub type ShortEventId = ShortId;
|
pub type ShortEventId = ShortId;
|
||||||
@@ -16,8 +15,8 @@ impl From<RawId> for Id {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn from(raw: RawId) -> Self {
|
fn from(raw: RawId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
shortroomid: u64_from_u8x8(raw.shortroomid()),
|
shortroomid: u64::from_be_bytes(raw.shortroomid()),
|
||||||
shorteventid: Count::from_unsigned(u64_from_u8x8(raw.shorteventid())),
|
shorteventid: Count::from_unsigned(u64::from_be_bytes(raw.shorteventid())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub fn pretty(bytes: usize) -> String {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn increment(old: Option<&[u8]>) -> [u8; 8] {
|
pub fn increment(old: Option<&[u8]>) -> [u8; 8] {
|
||||||
old.map_or(0_u64, u64_from_bytes_or_zero)
|
old.map_or(0_u64, |bytes| u64_from_bytes(bytes).unwrap_or(0))
|
||||||
.wrapping_add(1)
|
.wrapping_add(1)
|
||||||
.to_be_bytes()
|
.to_be_bytes()
|
||||||
}
|
}
|
||||||
@@ -45,16 +45,4 @@ pub fn u64_from_u8(bytes: &[u8]) -> u64 {
|
|||||||
|
|
||||||
/// Parses the big-endian bytes into an u64.
|
/// Parses the big-endian bytes into an u64.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
pub fn u64_from_bytes(bytes: &[u8]) -> Result<u64> { Ok(u64::from_be_bytes(bytes.try_into()?)) }
|
||||||
pub fn u64_from_bytes_or_zero(bytes: &[u8]) -> u64 { u64_from_bytes(bytes).unwrap_or(0) }
|
|
||||||
|
|
||||||
/// Parses the big-endian bytes into an u64.
|
|
||||||
#[inline]
|
|
||||||
pub fn u64_from_bytes(bytes: &[u8]) -> Result<u64> { Ok(u64_from_u8x8(*u8x8_from_bytes(bytes)?)) }
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
|
||||||
pub fn u64_from_u8x8(bytes: [u8; 8]) -> u64 { u64::from_be_bytes(bytes) }
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn u8x8_from_bytes(bytes: &[u8]) -> Result<&[u8; 8]> { Ok(bytes.try_into()?) }
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
use std::fmt;
|
|
||||||
|
|
||||||
/// Wrapper struct which will emit the HTML-escaped version of the contained
|
|
||||||
/// string when passed to a format string.
|
|
||||||
pub struct Escape<'a>(pub &'a str);
|
|
||||||
|
|
||||||
/// Copied from librustdoc:
|
|
||||||
/// * <https://github.com/rust-lang/rust/blob/cbaeec14f90b59a91a6b0f17fc046c66fa811892/src/librustdoc/html/escape.rs>
|
|
||||||
#[allow(clippy::string_slice)]
|
|
||||||
impl fmt::Display for Escape<'_> {
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
// Because the internet is always right, turns out there's not that many
|
|
||||||
// characters to escape: http://stackoverflow.com/questions/7381974
|
|
||||||
let Escape(s) = *self;
|
|
||||||
let pile_o_bits = s;
|
|
||||||
let mut last = 0;
|
|
||||||
for (i, ch) in s.char_indices() {
|
|
||||||
let s = match ch {
|
|
||||||
| '>' => ">",
|
|
||||||
| '<' => "<",
|
|
||||||
| '&' => "&",
|
|
||||||
| '\'' => "'",
|
|
||||||
| '"' => """,
|
|
||||||
| _ => continue,
|
|
||||||
};
|
|
||||||
|
|
||||||
fmt.write_str(&pile_o_bits[last..i])?;
|
|
||||||
fmt.write_str(s)?;
|
|
||||||
|
|
||||||
// NOTE: we only expect single byte characters here - which is fine as long as
|
|
||||||
// we only match single byte characters
|
|
||||||
last = i.saturating_add(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if last < s.len() {
|
|
||||||
fmt.write_str(&pile_o_bits[last..])?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
mod expected;
|
mod expected;
|
||||||
mod tried;
|
mod tried;
|
||||||
|
|
||||||
use std::{cmp, convert::TryFrom};
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
pub use checked_ops::checked_ops;
|
pub use checked_ops::checked_ops;
|
||||||
|
|
||||||
@@ -97,17 +97,11 @@ pub fn usize_from_u64_truncated(val: u64) -> usize { val as usize }
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn try_into<Dst: TryFrom<Src>, Src>(src: Src) -> Result<Dst> {
|
pub fn try_into<Dst: TryFrom<Src>, Src>(src: Src) -> Result<Dst> {
|
||||||
Dst::try_from(src).map_err(try_into_err::<Dst, Src>)
|
Dst::try_from(src).map_err(|_| {
|
||||||
|
err!(Arithmetic(
|
||||||
|
"failed to convert from {} to {}",
|
||||||
|
type_name::<Src>(),
|
||||||
|
type_name::<Dst>()
|
||||||
|
))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_into_err<Dst: TryFrom<Src>, Src>(e: <Dst as TryFrom<Src>>::Error) -> Error {
|
|
||||||
drop(e);
|
|
||||||
err!(Arithmetic(
|
|
||||||
"failed to convert from {} to {}",
|
|
||||||
type_name::<Src>(),
|
|
||||||
type_name::<Dst>()
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn clamp<T: Ord>(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) }
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ pub mod debug;
|
|||||||
pub mod defer;
|
pub mod defer;
|
||||||
pub mod future;
|
pub mod future;
|
||||||
pub mod hash;
|
pub mod hash;
|
||||||
pub mod html;
|
|
||||||
pub mod json;
|
pub mod json;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
pub mod mutex_map;
|
pub mod mutex_map;
|
||||||
@@ -27,13 +26,11 @@ pub use ::tuwunel_macros::implement;
|
|||||||
pub use self::{
|
pub use self::{
|
||||||
arrayvec::ArrayVecExt,
|
arrayvec::ArrayVecExt,
|
||||||
bool::BoolExt,
|
bool::BoolExt,
|
||||||
bytes::{increment, u64_from_bytes, u64_from_u8, u64_from_u8x8},
|
bytes::{increment, u64_from_bytes, u64_from_u8},
|
||||||
debug::slice_truncated as debug_slice_truncated,
|
debug::slice_truncated as debug_slice_truncated,
|
||||||
future::{BoolExt as FutureBoolExt, OptionStream, TryExtExt as TryFutureExtExt},
|
future::{BoolExt as FutureBoolExt, OptionStream, TryExtExt as TryFutureExtExt},
|
||||||
hash::sha256::delimited as calculate_hash,
|
hash::sha256::delimited as calculate_hash,
|
||||||
html::Escape as HtmlEscape,
|
|
||||||
json::{deserialize_from_str, to_canonical_object},
|
json::{deserialize_from_str, to_canonical_object},
|
||||||
math::clamp,
|
|
||||||
mutex_map::{Guard as MutexMapGuard, MutexMap},
|
mutex_map::{Guard as MutexMapGuard, MutexMap},
|
||||||
rand::{shuffle, string as random_string},
|
rand::{shuffle, string as random_string},
|
||||||
stream::{IterStream, ReadyExt, Tools as StreamTools, TryReadyExt},
|
stream::{IterStream, ReadyExt, Tools as StreamTools, TryReadyExt},
|
||||||
|
|||||||
Reference in New Issue
Block a user