1
0
Fork 0
forked from wry/wry

autocommit 2022-05-01 17:23:55 CEST

This commit is contained in:
Julian Orth 2022-05-01 17:23:55 +02:00
parent 4373ed05bf
commit e1d5bf0e5d
39 changed files with 1772 additions and 57 deletions

View file

@ -14,7 +14,7 @@ impl Bitfield {
let idx = val as usize / SEG_SIZE;
let pos = val as usize % SEG_SIZE;
while self.vals.len() <= idx {
self.vals.push(0);
self.vals.push(!0);
}
self.vals[idx] &= !(1 << pos);
}

View file

@ -12,7 +12,7 @@ use {
},
};
pub struct CloneCell<T: UnsafeCellCloneSafe> {
pub struct CloneCell<T> {
data: UnsafeCell<T>,
}
@ -26,19 +26,22 @@ impl<T: UnsafeCellCloneSafe> Clone for CloneCell<T> {
impl<T: UnsafeCellCloneSafe + Debug> Debug for CloneCell<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
unsafe { self.data.get().deref().fmt(f) }
self.get().fmt(f)
}
}
impl<T: UnsafeCellCloneSafe> CloneCell<T> {
pub fn new(t: T) -> Self {
impl<T> CloneCell<T> {
pub const fn new(t: T) -> Self {
Self {
data: UnsafeCell::new(t),
}
}
#[inline(always)]
pub fn get(&self) -> T {
pub fn get(&self) -> T
where
T: UnsafeCellCloneSafe,
{
unsafe { self.data.get().deref().clone() }
}
@ -52,7 +55,7 @@ impl<T: UnsafeCellCloneSafe> CloneCell<T> {
where
T: Default,
{
unsafe { mem::take(self.data.get().deref_mut()) }
self.set(T::default())
}
}

View file

@ -37,10 +37,8 @@ impl<K: Eq + Hash, V> CopyHashMap<K, V> {
Self::default()
}
pub fn set(&self, k: K, v: V) {
unsafe {
self.map.get().deref_mut().insert(k, v);
}
pub fn set(&self, k: K, v: V) -> Option<V> {
unsafe { self.map.get().deref_mut().insert(k, v) }
}
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<V>

View file

@ -204,3 +204,17 @@ impl Display for OsError {
write!(f, "{} (os error {})", msg, self.0)
}
}
pub trait OsErrorExt {
type Container;
fn to_os_error(self) -> Self::Container;
}
impl<T> OsErrorExt for Result<T, Errno> {
type Container = Result<T, OsError>;
fn to_os_error(self) -> Self::Container {
self.map_err(|e| e.into())
}
}