Crate cowstr

source ·
Expand description

This library defines strings with copy-on-write semantics.

CowStr

Is a String that can be initialized to a static string or be build dynamically. Its contents can then be immutably shared. When mutation is required the string will be copied first.

CowStr implements many of the std::String methods. Missing methods will be added as required, PR’s are welcome.

SubStr

Refers to an immutable slice inside of a CowStr. This resembles the &str/String relationship.

Features

  • multithreaded using ‘parking_lot’ for mutexes and atomics. This is the default.

When multithreaded is explicitly disabled a ligher Cell based reference counting and no Mutexes are used. This singlethreaded variant should only be used for applications that are designed to be single threaded on architectures where atomics are expensive.

Structs

  • Tried to try_push*() more than the strings spare capacity can hold.
  • A shared string that is copy-on-write and can be either static or dynamic shared with a reference counter. When a CowStr is dynamically created it can be mutated until it becomes cloned, then mutation becomes copy-on-write as marked with copy-on-write below.
  • Tried to use a range larger than the string it should cover.
  • Arbitrary immutable text as span from some shared string

Statics