Skip to content

Add WString::{from_raw_parts, into_raw_parts} #4

Description

@redfire75369

I am working on a JavaScript runtime, and I would like to add a no-copy way to send strings to the JS engine. The API for this requires me to pass in a raw *const u16 along with its length. (The problem of u16 vs u8 is not an issue here.)

It would be nice for there to be functions as follows:

impl<Endian> WString<Endian> {
  pub unsafe fn from_raw_parts(ptr: *mut u8, len: usize, capacity: usize) -> Self;
  pub fn into_raw_parts(self) -> (*mut u8, usize, usize);
}

I am aware this can be emulated with WString::into_bytes, followed by the same functions on Vec but it would be more convenient to have them on WString directly and would also bypass the process of checking the bytes are valid UTF-16.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions