Module inlinable_string::inline_string[][src]

Expand description

A short UTF-8 string that uses inline storage and does no heap allocation. It may be no longer than INLINE_STRING_CAPACITY bytes long.

The capacity restriction makes many operations that would otherwise be infallible on std::string::String fallible. Additionally, many trait interfaces don’t allow returning an error when a string runs out of space, and so the trait implementation simply panics. As such, InlineString does not implement StringExt and is not a drop-in replacement for std::string::String in the way that inlinable_string::InlinableString aims to be, and is generally difficult to work with. It is not recommended to use this type directly unless you really, really want to avoid heap allocation, can live with the imposed size restrictions, and are willing work around potential sources of panics (eg, in the From trait implementation).

Examples

use inlinable_string::InlineString;

let mut s = InlineString::new();
assert!(s.push_str("hi world").is_ok());
assert_eq!(s, "hi world");

assert!(s.push_str("a really long string that is much bigger than `INLINE_STRING_CAPACITY`").is_err());
assert_eq!(s, "hi world");

Structs

A short UTF-8 string that uses inline storage and does no heap allocation.

The error returned when there is not enough space in a InlineString for the requested operation.

Constants

The capacity (in bytes) of inline storage for small strings. InlineString::len() may never be larger than this.