[][src]Crate arcstr

Various implementations of Arc<str>-like types.

Well, just the one at the moment: ArcStr, which has the following benefits over Arc<str>:

  • Only a single pointer. Great for cases where you want to keep the data structure lightweight or need to do some FFI stuff with it.

  • It's possible to create a const arcstr from a literal via the literal_arcstr! macro.

    These are zero cost, take no heap allocation, and don't even need to perform atomic reads/writes when being cloned or dropped (or at any other time). They even get stored in the read-only memory of your executable, which can be beneficial for performance and memory usage. (The downside is that the API is a bit janky, see it's docs for why).

  • ArcStr::new() is a const function. This shouldn't be surprising given point 2 though. Naturally, this means that ArcStr::default() is free (unlike std::sync::Arc<str>::default()).

  • ArcStr is totally immutable. No need to lose sleep over code that thinks it has a right to mutate your Arc just because it holds the only reference.

  • More implementations of various traits PartialEq<Other> and other traits that hopefully will help improve ergonomics.

  • We don't support Weak references, which means the overhead of atomic operations is lower.

Planned or incomplete funtionality

Substr Type

Essentially an ergonomic (ArcStr, Range<usize>), which can be used to avoid allocation when creating a lot of ranges over the same string. A use case for this is parsers and lexers (Note that in practice I might use Range<u32> and not Range<usize>).

Key type.

Essentially this will be an 8-byte wrapper around ArcStr that allows storing small 7b-or-fewer strings inline, without allocation. It will be 8 bytes on 32-bit and 64-bit platforms, since 3b-or-fewer is not compelling.

Actually, I need to do some invesigation that 7b isn't too small too. The idea is for use as map keys or other small frequently repeated identifiers.

Macros

literal_arcstr

Create a const ArcStr from a (byte-string) literal. The resulting ArcStr require no heap allocation, can be freely cloned and used interchangeably with ArcStrs from the heap, and are effectively "free".

Structs

ArcStr

A better atomically-reference counted string type.