mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-13 14:39:25 +00:00
Port common, and most of crypto, to a more aggressive clippy
This commit is contained in:
@@ -24,14 +24,17 @@ mod shims {
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn new<E: 'static + Send + Sync>(kind: ErrorKind, error: E) -> Error {
|
||||
Error { kind, error: Box::new(error) }
|
||||
#[must_use]
|
||||
pub fn new<E: 'static + Send + Sync>(kind: ErrorKind, error: E) -> Self {
|
||||
Self { kind, error: Box::new(error) }
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> ErrorKind {
|
||||
#[must_use]
|
||||
pub const fn kind(&self) -> ErrorKind {
|
||||
self.kind
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn into_inner(self) -> Option<Box<dyn Send + Sync>> {
|
||||
Some(self.error)
|
||||
}
|
||||
@@ -53,10 +56,7 @@ mod shims {
|
||||
|
||||
impl Read for &[u8] {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||
let mut read = buf.len();
|
||||
if self.len() < buf.len() {
|
||||
read = self.len();
|
||||
}
|
||||
let read = self.len().min(buf.len());
|
||||
buf[.. read].copy_from_slice(&self[.. read]);
|
||||
*self = &self[read ..];
|
||||
Ok(read)
|
||||
|
||||
@@ -2,33 +2,20 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[allow(unused_imports)]
|
||||
#[doc(hidden)]
|
||||
#[macro_use]
|
||||
pub extern crate alloc;
|
||||
extern crate alloc;
|
||||
|
||||
pub mod sync;
|
||||
pub mod collections;
|
||||
pub mod io;
|
||||
|
||||
pub mod vec {
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use alloc::vec::*;
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::vec::*;
|
||||
}
|
||||
|
||||
pub mod str {
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use alloc::str::*;
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::str::*;
|
||||
}
|
||||
|
||||
pub mod string {
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use alloc::string::*;
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::string::*;
|
||||
}
|
||||
|
||||
@@ -32,24 +32,24 @@ mod oncelock_shim {
|
||||
|
||||
pub struct OnceLock<T>(Mutex<bool>, Option<T>);
|
||||
impl<T> OnceLock<T> {
|
||||
pub const fn new() -> OnceLock<T> {
|
||||
OnceLock(Mutex::new(false), None)
|
||||
pub const fn new() -> Self {
|
||||
Self(Mutex::new(false), None)
|
||||
}
|
||||
|
||||
// These return a distinct Option in case of None so another caller using get_or_init doesn't
|
||||
// transform it from None to Some
|
||||
pub fn get(&self) -> Option<&T> {
|
||||
if !*self.0.lock() {
|
||||
None
|
||||
} else {
|
||||
if *self.0.lock() {
|
||||
self.1.as_ref()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
pub fn get_mut(&mut self) -> Option<&mut T> {
|
||||
if !*self.0.lock() {
|
||||
None
|
||||
} else {
|
||||
if *self.0.lock() {
|
||||
self.1.as_mut()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ mod oncelock_shim {
|
||||
let mut lock = self.0.lock();
|
||||
if !*lock {
|
||||
unsafe {
|
||||
(core::ptr::addr_of!(self.1) as *mut Option<_>).write_unaligned(Some(f()));
|
||||
core::ptr::addr_of!(self.1).cast_mut().write_unaligned(Some(f()));
|
||||
}
|
||||
}
|
||||
*lock = true;
|
||||
|
||||
Reference in New Issue
Block a user