Skip to main content

Crate mago_atom

Crate mago_atom 

Source
Expand description

A high-performance, globally-interned string library for the Mago ecosystem.

This crate provides Atom, a canonical string type that guarantees any given string is stored in memory only once. It acts as a wrapper for the ustr crate and adds highly-optimized constructors for common string manipulations like lowercasing, concatenation, and number formatting.

The key feature is the ability to perform these operations without heap allocations for common cases by using stack-allocated buffers, making this crate ideal for performance-critical code.

§Usage

use mago_atom::*;

// Create an Atom. This is a cheap lookup in a global cache.
let s1 = atom("Hello");

// Use an optimized, zero-heap-allocation constructor.
let s2 = ascii_lowercase_atom("Hello");

assert_eq!(s2.as_str(), "hello");

// Use the specialized, high-performance map.
let mut map = AtomMap::default();
map.insert(s1, 123);

Macros§

concat_atom
A macro to concatenate between 2 and 12 string slices into a single Atom.

Structs§

Atom
A handle representing a string in the global string cache.

Functions§

ascii_lowercase_atom
Creates an Atom from a lowercased version of a string slice.
ascii_lowercase_constant_name_atom
Creates an Atom from a constant name, lowercasing only the namespace part.
atom
Create a new Ustr from the given str.
concat_atom2
Creates an Atom as a result of concatenating 2 string slices.
concat_atom3
Creates an Atom as a result of concatenating 3 string slices.
concat_atom4
Creates an Atom as a result of concatenating 4 string slices.
concat_atom5
Creates an Atom as a result of concatenating 5 string slices.
concat_atom6
Creates an Atom as a result of concatenating 6 string slices.
concat_atom7
Creates an Atom as a result of concatenating 7 string slices.
concat_atom8
Creates an Atom as a result of concatenating 8 string slices.
concat_atom9
Creates an Atom as a result of concatenating 9 string slices.
concat_atom10
Creates an Atom as a result of concatenating 10 string slices.
concat_atom11
Creates an Atom as a result of concatenating 11 string slices.
concat_atom12
Creates an Atom as a result of concatenating 12 string slices.
empty_atom
Returns the canonical Atom for an empty string.
f32_atom
Creates an Atom from a f32 value with zero heap allocations.
f64_atom
Creates an Atom from a f64 value with zero heap allocations.
i8_atom
Creates an Atom from a i8 value with zero heap allocations.
i16_atom
Creates an Atom from a i16 value with zero heap allocations.
i32_atom
Creates an Atom from a i32 value with zero heap allocations.
i64_atom
Creates an Atom from a i64 value with zero heap allocations.
i128_atom
Creates an Atom from a i128 value with zero heap allocations.
isize_atom
Creates an Atom from a isize value with zero heap allocations.
starts_with_ignore_case
Checks if haystack starts with prefix, ignoring ASCII case.
u8_atom
Creates an Atom from a u8 value with zero heap allocations.
u16_atom
Creates an Atom from a u16 value with zero heap allocations.
u32_atom
Creates an Atom from a u32 value with zero heap allocations.
u64_atom
Creates an Atom from a u64 value with zero heap allocations.
u128_atom
Creates an Atom from a u128 value with zero heap allocations.
usize_atom
Creates an Atom from a usize value with zero heap allocations.

Type Aliases§

AtomMap
A high-performance HashMap using Atom as the key.
AtomSet
A high-performance HashSet using Atom as the key.