[][src]Crate mangling

This crate provides for converting arbitrary byte streams into valid C-language identifiers ("mangled names") and back again.

Rationale

The functionality of this crate was hoisted out of a compiler that needed to translate identifiers for Java symbols (e.g. method names and signatures) into symbols valid for the generated assembly language. Although the mangling process can encode any stream of bytes into a (longer) string of ASCII characters, and then convert the output back again, it is not intended to provide general encoding/decoding facilities. Instead, it is meant to provide an easy, reliable way for compiler writers to generate human-recognizable identifiers without having to invent their own mangling scheme.

Requirements

  1. Totality (every byte stream can be encoded into a unique mangled name)
  2. Injectivity (each mangled name can be decoded to a unique byte stream)

Goals

  1. Correctness (the implementation matches its documented behavior)
  2. Consistency (the implementation behaves in a predictable manner)
  3. Readability (mangled names are visibly related to input streams)
  4. Compactness (mangled names are comparable in length to inputs)
  5. Performance (processing is computationally efficient in time and space)

Modules

clib

Provides C-compatible interfaces to mangle and demangle functions.

Functions

demangle

Takes a string slice corresponding to a symbol as converted by the mangle function, and returns a vector of bytes corresponding to the original input to the mangle function.

mangle

Takes an IntoIterator over u8 and produces a String that is safe to use as an identifier in the C language.