summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-04 09:30:44 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-04 11:38:09 +0100
commiteb951c008beea502042db4a3a0e8d1f8b51f6f52 (patch)
tree9856ee4ed0222222669de10e616a580b2a60135e /src/util
parent33928a00dc58250e24da1dae4e5db17e7b598d70 (diff)
Style changes
Diffstat (limited to 'src/util')
-rw-r--r--src/util/eco.rs26
-rw-r--r--src/util/fat.rs20
-rw-r--r--src/util/mod.rs6
3 files changed, 20 insertions, 32 deletions
diff --git a/src/util/eco.rs b/src/util/eco.rs
index 800760e2..5a4d7629 100644
--- a/src/util/eco.rs
+++ b/src/util/eco.rs
@@ -68,7 +68,7 @@ impl EcoString {
let len = slice.len();
Self(if len <= LIMIT {
let mut buf = [0; LIMIT];
- buf[.. len].copy_from_slice(slice.as_bytes());
+ buf[..len].copy_from_slice(slice.as_bytes());
Repr::Small { buf, len: len as u8 }
} else {
Repr::Large(Arc::new(s.into()))
@@ -116,7 +116,7 @@ impl EcoString {
let prev = usize::from(*len);
let new = prev + string.len();
if new <= LIMIT {
- buf[prev .. new].copy_from_slice(string.as_bytes());
+ buf[prev..new].copy_from_slice(string.as_bytes());
*len = new as u8;
} else {
let mut spilled = String::with_capacity(new);
@@ -161,7 +161,7 @@ impl EcoString {
pub fn to_lowercase(&self) -> Self {
if let Repr::Small { mut buf, len } = self.0 {
if self.is_ascii() {
- buf[.. usize::from(len)].make_ascii_lowercase();
+ buf[..usize::from(len)].make_ascii_lowercase();
return Self(Repr::Small { buf, len });
}
}
@@ -173,7 +173,7 @@ impl EcoString {
pub fn to_uppercase(&self) -> Self {
if let Repr::Small { mut buf, len } = self.0 {
if self.is_ascii() {
- buf[.. usize::from(len)].make_ascii_uppercase();
+ buf[..usize::from(len)].make_ascii_uppercase();
return Self(Repr::Small { buf, len });
}
}
@@ -191,10 +191,10 @@ impl EcoString {
let prev = usize::from(len);
let new = prev.saturating_mul(n);
if new <= LIMIT {
- let src = &buf[.. prev];
+ let src = &buf[..prev];
let mut buf = [0; LIMIT];
- for i in 0 .. n {
- buf[prev * i .. prev * (i + 1)].copy_from_slice(src);
+ for i in 0..n {
+ buf[prev * i..prev * (i + 1)].copy_from_slice(src);
}
return Self(Repr::Small { buf, len: new as u8 });
}
@@ -217,7 +217,7 @@ impl Deref for EcoString {
// Furthermore, we still do the bounds-check on the len in case
// it gets corrupted somehow.
Repr::Small { buf, len } => unsafe {
- std::str::from_utf8_unchecked(&buf[.. usize::from(*len)])
+ std::str::from_utf8_unchecked(&buf[..usize::from(*len)])
},
Repr::Large(string) => string.as_str(),
}
@@ -398,9 +398,9 @@ mod tests {
assert_eq!(EcoString::from("abc"), "abc");
// Test around the inline limit.
- assert_eq!(EcoString::from(&ALPH[.. LIMIT - 1]), ALPH[.. LIMIT - 1]);
- assert_eq!(EcoString::from(&ALPH[.. LIMIT]), ALPH[.. LIMIT]);
- assert_eq!(EcoString::from(&ALPH[.. LIMIT + 1]), ALPH[.. LIMIT + 1]);
+ assert_eq!(EcoString::from(&ALPH[..LIMIT - 1]), ALPH[..LIMIT - 1]);
+ assert_eq!(EcoString::from(&ALPH[..LIMIT]), ALPH[..LIMIT]);
+ assert_eq!(EcoString::from(&ALPH[..LIMIT + 1]), ALPH[..LIMIT + 1]);
// Test heap string.
assert_eq!(EcoString::from(ALPH), ALPH);
@@ -443,7 +443,7 @@ mod tests {
assert_eq!(v, "Hello World");
// Remove one-by-one.
- for _ in 0 .. 10 {
+ for _ in 0..10 {
v.pop();
}
@@ -462,7 +462,7 @@ mod tests {
fn test_str_index() {
// Test that we can use the index syntax.
let v = EcoString::from("abc");
- assert_eq!(&v[.. 2], "ab");
+ assert_eq!(&v[..2], "ab");
}
#[test]
diff --git a/src/util/fat.rs b/src/util/fat.rs
index bb557bc9..728f6ae8 100644
--- a/src/util/fat.rs
+++ b/src/util/fat.rs
@@ -5,7 +5,7 @@
//! pointer metadata APIs are stable, we should definitely move to them:
//! <https://github.com/rust-lang/rust/issues/81513>
-use std::alloc;
+use std::alloc::Layout;
use std::mem;
/// Create a fat pointer from a data address and a vtable address.
@@ -15,12 +15,8 @@ use std::mem;
/// to a value whose type implements the trait of `T` and the `vtable` must have
/// been extracted with [`vtable`].
pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *const T {
- debug_assert_eq!(
- alloc::Layout::new::<*const T>(),
- alloc::Layout::new::<FatPointer>(),
- );
-
let fat = FatPointer { data, vtable };
+ debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>());
mem::transmute_copy::<FatPointer, *const T>(&fat)
}
@@ -31,12 +27,8 @@ pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *
/// to a value whose type implements the trait of `T` and the `vtable` must have
/// been extracted with [`vtable`].
pub unsafe fn from_raw_parts_mut<T: ?Sized>(data: *mut (), vtable: *const ()) -> *mut T {
- debug_assert_eq!(
- alloc::Layout::new::<*mut T>(),
- alloc::Layout::new::<FatPointer>(),
- );
-
let fat = FatPointer { data, vtable };
+ debug_assert_eq!(Layout::new::<*mut T>(), Layout::new::<FatPointer>());
mem::transmute_copy::<FatPointer, *mut T>(&fat)
}
@@ -45,11 +37,7 @@ pub unsafe fn from_raw_parts_mut<T: ?Sized>(data: *mut (), vtable: *const ()) ->
/// # Safety
/// Must only be called when `T` is a `dyn Trait`.
pub unsafe fn vtable<T: ?Sized>(ptr: *const T) -> *const () {
- debug_assert_eq!(
- alloc::Layout::new::<*const T>(),
- alloc::Layout::new::<FatPointer>(),
- );
-
+ debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>());
mem::transmute_copy::<*const T, FatPointer>(&ptr).vtable
}
diff --git a/src/util/mod.rs b/src/util/mod.rs
index df3c446e..c6809d23 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -2,13 +2,13 @@
pub mod fat;
-pub use buffer::Buffer;
-pub use eco::{format_eco, EcoString};
-
#[macro_use]
mod eco;
mod buffer;
+pub use buffer::Buffer;
+pub use eco::{format_eco, EcoString};
+
use std::any::TypeId;
use std::fmt::{self, Debug, Formatter};
use std::hash::Hash;