-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add from_slice to VirtAddr #442
Conversation
Is that a problem though? Can't we just cast through a thin pointer? i.e. pub fn from_ptr<T>(ptr: *const T) -> Self
where
T: ?Sized,
{
Self::new(ptr as *const () as u64)
} |
I like this approach for adding support for |
I did not think of casting to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, could we add a unit test for using from_ptr
with an unsized argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
Normally it's easily possible to create a
VirtAddr
via a reference using thefrom_ptr
function. However this doesn't work with slices, because they are unsized.My first idea was to simply modify
from_ptr<T>
tofrom_ptr<T: Sized?>
, however that does not work because slices are wide pointers and therefor have to be cast into a narrow pointer first.