Expand description
§Pascal strings in Rust.
A PascalString
, or ShortString
is a String which stores its data on the stack. Because of this, it has
a fixed maximum size, which cannot be changed. Traditionally, the size of a PascalString
is 256 bytes -
the first byte stores the length, which means that each remaining byte is indexable using only that byte.
This is a very niche string type - generally, you are better off using std::string::String
, or the
AsciiString
type from the ascii
crate if you need an ascii string. They have no upper size limit, and
are cheaper to pass around as they are only 64 bytes on the stack. Generally, you should only use PascalString
if:
- You know that you absolutely, certainly cannot do without heap allocation.
- You need to store your string data inline into your
struct
type - for example if you will allocate a bunch of these customstruct
types into a pool allocator, and cannot afford the heap fragmentation. - You will keep, allocate, and deallocate a lot of short strings in your program.
Structs§
- Chars
- An immutable iterator over the buffer of a
PascalStr
. - Chars
Mut - A mutable iterator over the buffer of a
PascalStr
. - Into
Chars - An iterator over the buffer of a
PascalString
. Has ownership of the iteratedPascalString
. - Lines
- An iterator over the lines of the internal character array.
- Pascal
Str - A borrowed slice from a
PascalString
. Does not own its data. - Pascal
String - An owned
PascalString
. This string type stores its data the stack. It is always 256 bytes long, with the first byte storing the length.
Enums§
- Ascii
Error - An error type which abstracts over ascii conversion errors.
- Pascal
String Append Error - Indicates the range of errors which can occur from appending string data to a
PascalString
. - Pascal
String Create Error - Indicates the range of errors which can occur from creating a new
PascalString
.