hsivonen / hsivonen/encoding_rs

Encoding::decode_to_utf16 ?

Open
#24 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
464
Forks
70
Avg merge
2d 4h
Merged PRs (30d)
2

Description

I’ve just written this function:

fn decode_to_utf16(bytes: &[u8], encoding: &'static Encoding) -> Vec<u16> {
    let mut decoder = encoding.new_decoder();
    let capacity = decoder.max_utf16_buffer_length(bytes.len()).exepct("Overflow");
    let mut utf16 = Vec::with_capacity(capacity);
    let uninitialized = unsafe {
        slice::from_raw_parts_mut(utf16.as_ptr(), capacity)
    };
    let last = true;
    let (_, read, written, _) = decoder.decode_to_utf16(bytes, uninitialized, last);
    assert!(read == bytes.len());
    unsafe {
        utf16.set_len(written)
    }
    utf16
}

Do you think it would belong as a method of Encoding?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's decode_to_utf16 function and the Encoding API, then inspect how similar decoding helpers are exposed in the project. Determine whether this belongs as an Encoding method or remains a standalone helper; the issue does not name files or tests that define completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.