pchickey labeled Issue #1888:
This issue is specific to the Wiggle crate. It is a good beginner issue.
Feature
We don't have a way to convert between GuestPtr<[u8]> and GuestPtr<str>. I just came across a case where it would be useful - I have a
GuestPtr<str>
and I need to pass the underlying data as&[u8]
to a function that will perform its own utf8 validation - and the opposite is probably useful as well. #### BenefitImplementation
Add methods to
impl GuestPtr<[T]>
and implGuestPtr<str>
that return the other type.
pchickey opened Issue #1888:
This issue is specific to the Wiggle crate. It is a good beginner issue.
Feature
We don't have a way to convert between GuestPtr<[u8]> and GuestPtr<str>. I just came across a case where it would be useful - I have a
GuestPtr<str>
and I need to pass the underlying data as&[u8]
to a function that will perform its own utf8 validation - and the opposite is probably useful as well. #### BenefitImplementation
Add methods to
impl GuestPtr<[T]>
and implGuestPtr<str>
that return the other type.
pchickey edited Issue #1888:
This issue is specific to the Wiggle crate. It is a good beginner issue.
Feature
We don't have a way to convert between GuestPtr<[u8]> and GuestPtr<str>. I just came across a case where it would be useful - I have a
GuestPtr<str>
and I need to pass the underlying data as&[u8]
to a function that will perform its own utf8 validation - and the opposite is probably useful as well.Implementation
Add methods to
impl GuestPtr<[T]>
and implGuestPtr<str>
that return the other type.
siyopao commented on Issue #1888:
Hi! Would it be okay if I took a shot at this? Although I may require a bit more explanation...
pchickey commented on Issue #1888:
Welcome @siyopao, thank you for volunteering!
In the wiggle crate, we have three impls of the
Pointee
trait that describe how we keep track of pointers to atomic valuesT
, slices[T]
, and stringsstr
. A string is just a[u8]
which contains valid utf-8 codepoints.One mechanic of
GuestPtr
is we check for validity of the contents not when theGuestPtr
is constructed but when it is "dereferenced" - viaread
,as_slice
, oras_str
. So, the check for whether the contents of aGuestPtr<str>
are valid utf-8 doesn't occur untilGuestPtr::as_str
is invoked.If the user wishes to skip the utf-8 validity check, there is currently no way to take a
GuestPtr<str>
and treat it as aGuestPtr<[u8]>
, these are kept separate in the type system even though they have the sametype Pointer = (u32, u32);
indicating the start of, and length of, the linear memory region.So, I propose adding a method to
impl GuestPtr<str>
that has the signaturepub fn as_byte_ptr(&self) -> GuestPtr<[u8]>
, and a newimpl GuestPtr<[u8]>
that has a function with signaturepub fn as_str_ptr(&self) -> GuestPtr<str>
.
pchickey edited a comment on Issue #1888:
Welcome @siyopao, thank you for volunteering!
In the wiggle crate, we have three impls of the
Pointee
trait that describe how we keep track of pointers to atomic valuesT
, slices[T]
, and stringsstr
. A string is just a[u8]
which contains valid utf-8 codepoints.One mechanic of
GuestPtr
is we check for validity of the contents not when theGuestPtr
is constructed but when it is "dereferenced" - viaread
,as_slice
, oras_str
. So, the check for whether the contents of aGuestPtr<str>
are valid utf-8 doesn't occur untilGuestPtr::as_str
is invoked.If the user wishes to skip the utf-8 validity check, there is currently no way to take a
GuestPtr<str>
and treat it as aGuestPtr<[u8]>
, these are kept separate in the type system even though they have the sametype Pointer = (u32, u32);
indicating the start of, and length of, the linear memory region.So, I propose adding a method to
impl GuestPtr<str>
that has the signaturepub fn as_byte_ptr(&self) -> GuestPtr<[u8]>
, and a newimpl GuestPtr<[u8]>
that has a method with signaturepub fn as_str_ptr(&self) -> GuestPtr<str>
.
pchickey edited Issue #1888:
This issue is specific to the Wiggle crate. It is a good beginner issue.
Feature
We don't have a way to convert between
GuestPtr<[u8]>
andGuestPtr<str>
. I just came across a case where it would be useful - I have aGuestPtr<str>
and I need to pass the underlying data as&[u8]
to a function that will perform its own utf8 validation - and the opposite is probably useful as well.Implementation
Add methods to
impl GuestPtr<[u8]>
and implGuestPtr<str>
that return the other type.
pchickey edited a comment on Issue #1888:
Welcome @siyopao, thank you for volunteering!
In the wiggle crate, we have three impls of the
Pointee
trait that describe how we keep track of pointers to atomic valuesT
, slices[T]
, and stringsstr
. A string is just a[u8]
which contains valid utf-8 codepoints.One mechanic of
GuestPtr
is we check for validity of the contents not when theGuestPtr
is constructed but when it is "dereferenced" - viaread
,as_slice
, oras_str
. So, the check for whether the contents of aGuestPtr<str>
are valid utf-8 doesn't occur untilGuestPtr::as_str
is invoked.If the user wishes to skip the utf-8 validity check, there is currently no way to take a
GuestPtr<str>
and treat it as aGuestPtr<[u8]>
, these are kept separate in the type system even though they have the sametype Pointer = (u32, u32);
indicating the start of, and length of, the linear memory region they point to.So, I propose adding a method to
impl GuestPtr<str>
that has the signaturepub fn as_byte_ptr(&self) -> GuestPtr<[u8]>
, and a newimpl GuestPtr<[u8]>
that has a method with signaturepub fn as_str_ptr(&self) -> GuestPtr<str>
.
siyopao commented on Issue #1888:
Hello @pchickey! Wow, thank you for the in-depth explanation. Let me see what I can do :+1:
siyopao commented on Issue #1888:
Hi @pchickey. Again, thank you the the explanation. So I have started to take a look, and noticed that the implementation of
GuestPtr<str>
has a methodpub fn as_bytes(&self) -> GuestPtr<'a, [u8]> { GuestPtr::new(self.mem, self.pointer) }
Is this basically what your proposed
pub fn as_byte_ptr(&self) -> GuestPtr<[u8]>
would look like, or am I totally off base? Thank you!
pchickey commented on Issue #1888:
If that typechecks then it looks correct to me.
pchickey closed Issue #1888:
This issue is specific to the Wiggle crate. It is a good beginner issue.
Feature
We don't have a way to convert between
GuestPtr<[u8]>
andGuestPtr<str>
. I just came across a case where it would be useful - I have aGuestPtr<str>
and I need to pass the underlying data as&[u8]
to a function that will perform its own utf8 validation - and the opposite is probably useful as well.Implementation
Add methods to
impl GuestPtr<[u8]>
and implGuestPtr<str>
that return the other type.
Last updated: Dec 23 2024 at 12:05 UTC