Skip to content

Commit d891bdb

Browse files
authored
Merge pull request #442 from Wasabi375/master
add from_slice to VirtAddr
2 parents e3ab047 + 3844ef8 commit d891bdb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/addr.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ impl VirtAddr {
129129
// doesn't truncate.
130130
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
131131
#[inline]
132-
pub fn from_ptr<T>(ptr: *const T) -> Self {
133-
Self::new(ptr as u64)
132+
pub fn from_ptr<T: ?Sized>(ptr: *const T) -> Self {
133+
Self::new(ptr as *const () as u64)
134134
}
135135

136136
/// Converts the address to a raw pointer.
@@ -844,4 +844,11 @@ mod tests {
844844
fn test_phys_addr_align_up_overflow() {
845845
PhysAddr::new(0x000f_ffff_ffff_ffff).align_up(2u64);
846846
}
847+
848+
#[test]
849+
fn test_from_ptr_array() {
850+
let slice = &[1, 2, 3, 4, 5];
851+
// Make sure that from_ptr(slice) is the address of the first element
852+
assert_eq!(VirtAddr::from_ptr(slice), VirtAddr::from_ptr(&slice[0]));
853+
}
847854
}

0 commit comments

Comments
 (0)