Skip to content

Commit

Permalink
trait AsMutPtr: impl AsMutPtr for Box<[_]>.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Apr 13, 2024
1 parent 21c4993 commit 11afa8e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/disjoint_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::ops::RangeInclusive;
use std::ops::RangeTo;
use std::ops::RangeToInclusive;
use std::ptr;
use std::ptr::addr_of_mut;

use crate::src::align::AlignedByteChunk;
use crate::src::align::AlignedVec;
Expand Down Expand Up @@ -604,6 +605,19 @@ unsafe impl<V> AsMutPtr for [V] {
}
}

unsafe impl<V> AsMutPtr for Box<[V]> {
type Target = V;

unsafe fn as_mut_ptr(ptr: *mut Self) -> *mut Self::Target {
// SAFETY: `AsMutPtr::as_mut_ptr` may derefence `ptr`.
unsafe { addr_of_mut!(**ptr) }.cast()
}

fn len(&self) -> usize {
(**self).len()
}
}

impl<V: Copy, C: AlignedByteChunk> DisjointMut<AlignedVec<V, C>> {
pub fn resize(&mut self, new_len: usize, value: V) {
self.inner.get_mut().resize(new_len, value)
Expand Down

0 comments on commit 11afa8e

Please sign in to comment.