mangling

Crates.iomangling
lib.rsmangling
version0.2.4
sourcesrc
created_at2020-04-10 20:38:34.264061
updated_at2024-08-31 17:55:26.485928
descriptionmangling generates safe, recognizable identifiers from byte streams.
homepage
repositoryhttps://github.com/kulp/mangling
max_upload_size
id228462
size39,238
Darren Kulp (kulp)

documentation

README

mangling

crates.io Rust codecov Docs.rs

Purpose

This library provides for reversibly generating identifiers (hereinafter "mangled names") that are valid under C-language rules, from arbitrary byte streams, while maintaining a measure of human readability.

Examples

See lib.rs for examples of strings with their manglings.

Rationale

The functionality of mangling 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.

Features

Schemes

At present, only one mangling scheme is supported, with a fixed format defined in the library documentation. The mangling scheme is simple, and may not be original, but is not known to be shared with any other system, so no interoperability guarantees are provided. Future revisions may change the API to allow some level of configurability or replacement of the encoding 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)

Minimum Supported Rust Version

The minimum supported Rust version is documented in Cargo.toml via the rust-version key. The MSRV for mangling may change at any time, but usually for good reasons.

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)

Feedback

Any demonstrated failure of mangling to meet its stated requirements should be reported through Github, and pull requests are welcomed.

Commit count: 268

cargo fmt