Function map_into

Source
pub fn map_into(
    text: &BStr,
    dest: &mut Vec<u8>,
    options: &TransformOptions,
    func: Option<TransformCallback<'_>>,
) -> Result<(), Error>
Expand description

Apply a transformation to a string, indicated by the TransformOptions, writing the result into the specified destination byte-buffer.

Since this is the advanced interface, the result may not be valid Unicode. The input is not statically required to be valid UTF8 either, and invalid UTF8 will return a ErrorKind::InvalidUtf8.

May apply a user-specified transformation to each codepoint, before utf8proc does its own transformations. The callback is expected to be deterministic. If not, it could trigger unexpected panics (but not undefined behavior).

Implicitly allocates necessary space, so a InsufficientSpaceError is impossible.

ยงImplementation

This method is behaviorally equivalent to the utf8proc_map_custom function in the C library, but is reimplemented to have a couple major advantages:

  • Reuses a destination buffer instead of freshly allocating each time
  • Avoids calling decompose_buffer twice if buffer is already of sufficient length
  • Does not require the input buffer to be word-aligned
  • Uses rust allocator instead of C allocator
  • Does not implicitly add null terminator