string
import std::collections::string; · source
Types
String<A>
type struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
static new() -> String;
static new_in(alloc: A) -> String<A>;
static with_capacity(capacity: u64) -> String;
static try_with_capacity_in(capacity: u64, alloc: A) -> Result<String<A>, AllocError>;
static from_str(source: Str) -> String;
![implicit]
static from_string(text: string) -> String;
static with_null(source: Str) -> String;
static from<T>(item: T) -> String;
push<T>(mut &this, item: T) -> void;
try_push<T>(mut &this, item: T) -> Result<(), AllocError>;
push_byte(mut &this, byte: u8) -> void;
try_push_byte(mut &this, byte: u8) -> Result<(), AllocError>;
clear(mut &this) -> void;
length(&this) -> u64;
capacity(&this) -> u64;
is_empty(&this) -> boolean;
as_str(&this) -> Str;
as_bytes(&this) -> Slice<u8>;
as_ptr(&this) -> u8*;
as_cstr(mut &this) -> u8*;
into_raw(mut this) -> string;
starts_with(&this, prefix: &Str) -> boolean;
ends_with(&this, suffix: &Str) -> boolean;
find(&this, needle: &Str) -> Option<u64>;
contains(&this, needle: &Str) -> boolean;
trim(&this) -> Str;
trim_start(&this) -> Str;
trim_end(&this) -> Str;
to_ascii_uppercase(&this) -> String;
to_ascii_lowercase(&this) -> String;
split(&this, sep: &Str) -> SplitIter;
chars(&this) -> Chars;
char_indices(&this) -> CharIndices;
truncate(mut &this, new_length: u64) -> void;
reserve(mut &this, additional: u64) -> Result<(), AllocError>;
reserve_exact(mut &this, additional: u64) -> Result<(), AllocError>;
shrink_to_fit(mut &this) -> void;
}
The owned, growable companion to Str: a heap byte buffer plus a length. No NUL terminator, no encoding assumptions beyond "the bytes are valid UTF-8". The first allocation reserves 8 bytes.
Properties
| Property | Type |
|---|---|
buffer | RawBuffer<u8, A> |
length | u64 |
Constructors
static new() -> String;
static new() -> String;Empty string. No heap storage until the first push_* / reserve.
static new_in(alloc: A) -> String<A>;
static with_capacity(capacity: u64) -> String;
static with_capacity(capacity: u64) -> String;Preallocate room for capacity bytes. Panics on allocation failure.
static try_with_capacity_in(capacity: u64, alloc: A) -> Result<String<A>, AllocError>;
static from_str(source: Str) -> String;
static from_str(source: Str) -> String;Construct from a Str by copying its bytes. Panics on allocation failure.
![implicit] static from_string(text: string) -> String;
![implicit] static from_string(text: string) -> String;Construct an owned String from a string (Cryo's raw NUL-terminated C-string view) by copying its bytes. Marked ![implicit]: the compiler treats this as the constructor when a string flows into a String slot - a parameter (println("text")) or a typed binding (mut s: String = "text"). The resulting String owns its buffer and moves into the destination. Named for its source type (string), the mirror of from_str (which takes a Str); with_null is the inverse direction (produce a C-facing NUL-terminated buffer).
static with_null(source: Str) -> String;
static with_null(source: Str) -> String;Construct a NUL-terminated copy of source for handing to C. The terminating NUL lives in the buffer (so as_ptr() yields a valid const char*) but is excluded from the logical length, so as_str() / length() see only source. Matches C semantics on an interior NUL: the C side stops reading at the first one. This is the produce-for-C direction; from_string is the consume-from-C one. Pairs with the as_cstr() borrow method.
static from<T>(item: T) -> String;
static from<T>(item: T) -> String;Create a String from item, using the SAME compile-time static match (T) dispatch as push - the central T-generic constructor. String::from("hi"), String::from(65 as u32), String::from(true), String::from(some_str) all route through push. Panics on allocation failure.
Methods
push<T>(mut &this, item: T) -> void;
push<T>(mut &this, item: T) -> void;Append item to the string as its text representation, dispatched at compile time via static match (T) - no runtime cost, no trait bound, because the available arms ARE the accepted types: - Str / string - the view's / C string's UTF-8 bytes verbatim (a string's terminating NUL is not copied). - every primitive integer - its decimal Display text, e.g. (u8..u128, i8..i128, s.push(65 as u8) appends "65". usize / isize) - f32 / f64 - its Display text. - boolean - "true" / "false". Any other type is a compile error (the static match has no _ arm). To
try_push<T>(mut &this, item: T) -> Result<(), AllocError>;
try_push<T>(mut &this, item: T) -> Result<(), AllocError>;Fallible push: returns AllocError instead of panicking. Same compile-time dispatch as push.
push_byte(mut &this, byte: u8) -> void;
push_byte(mut &this, byte: u8) -> void;Append a single raw byte (not its decimal text). For byte-exact work: NUL terminators, control characters, binary buffers. The caller is responsible for keeping the string valid UTF-8. Panics on allocation failure; use try_push_byte for the fallible form.
try_push_byte(mut &this, byte: u8) -> Result<(), AllocError>;
try_push_byte(mut &this, byte: u8) -> Result<(), AllocError>;Fallible push_byte: append one raw byte, returning AllocError instead of panicking.
clear(mut &this) -> void;
length(&this) -> u64;
capacity(&this) -> u64;
is_empty(&this) -> boolean;
as_str(&this) -> Str;
as_str(&this) -> Str;Borrow as a Str. Invalidated by the next mutating call.
as_bytes(&this) -> Slice<u8>;
as_ptr(&this) -> u8*;
as_cstr(mut &this) -> u8*;
as_cstr(mut &this) -> u8*;Borrow this String as a NUL-terminated C string (u8* / const char*) for handing to an extern "C" API.
into_raw(mut this) -> string;
into_raw(mut this) -> string;Consume the String and return its NUL-terminated buffer as a raw string (C-string view), leaking the allocation so the caller owns the bytes with no borrow lifetime. A NUL terminator is appended first. The owning companion of Str::sub_bytes etc. for handing an owned C-string across the FFI / raw-string boundary.
starts_with(&this, prefix: &Str) -> boolean;
ends_with(&this, suffix: &Str) -> boolean;
find(&this, needle: &Str) -> Option<u64>;
contains(&this, needle: &Str) -> boolean;
trim(&this) -> Str;
trim(&this) -> Str;Borrowed sub-slice with surrounding ASCII whitespace removed.
trim_start(&this) -> Str;
trim_start(&this) -> Str;Borrowed sub-slice with leading ASCII whitespace removed. Mirrors Str::trim_start, closing the String vs Str method asymmetry.
trim_end(&this) -> Str;
trim_end(&this) -> Str;Borrowed sub-slice with trailing ASCII whitespace removed. Mirrors Str::trim_end.
to_ascii_uppercase(&this) -> String;
to_ascii_lowercase(&this) -> String;
to_ascii_lowercase(&this) -> String;Fresh String with every ASCII uppercase byte folded to lowercase. Mirrors Str::to_ascii_lowercase and the existing String::to_ascii_uppercase.
split(&this, sep: &Str) -> SplitIter;
split(&this, sep: &Str) -> SplitIter;Iterator over pieces separated by sep (borrows this String).
chars(&this) -> Chars;
chars(&this) -> Chars;Iterator over Unicode scalar values (u32), decoding UTF-8 on the fly. Borrows this String; see Str::chars.
char_indices(&this) -> CharIndices;
char_indices(&this) -> CharIndices;Iterator over (byte_offset, scalar) pairs. Borrows this String; see Str::char_indices.
truncate(mut &this, new_length: u64) -> void;
truncate(mut &this, new_length: u64) -> void;Shrink length to new_length. No reallocation; capacity is unchanged. Bytes beyond new_length are no longer considered part of the string; subsequent push_* calls will overwrite them.
reserve(mut &this, additional: u64) -> Result<(), AllocError>;
reserve_exact(mut &this, additional: u64) -> Result<(), AllocError>;
shrink_to_fit(mut &this) -> void;
Constructing
new and new_in allocate nothing until the first push; with_capacity preallocates, and try_with_capacity_in is its fallible form. from_string copies a C string and is marked ![implicit], so mut s: String = "text" and println("text") both route through it. from<T> is the general constructor — the same dispatch as push — and with_null keeps a trailing NUL for the FFI boundary.
Appending
push<T> appends item as its text representation, dispatched at compile time through static match (T) — no runtime cost and no trait bound, because the available arms are the accepted types:
String,Str, andstring— the UTF-8 bytes verbatim (astring's terminating NUL is not copied).- Every primitive integer,
usize, andisize— its decimal text.s.push(65 as u8)appends"65". f32andf64— theirDisplaytext.boolean—"true"or"false".
Anything else is a compile error; the static match has no _ arm.
mut s: String = String::new();
s.push("count: ");
s.push(42); // "count: 42"
s.push_byte(0x0A); // a raw newline byte
push_byte appends a single raw byte rather than its decimal text — for NUL terminators, control characters, and binary buffers. Keeping the result valid UTF-8 is your responsibility. Both have try_ forms returning Result<(), AllocError> instead of panicking.
Reading and borrowing
length(), capacity(), is_empty(), as_str() -> Str, as_bytes() -> Slice<u8>, as_ptr() -> u8*, plus clear(), truncate(new_length), reserve, reserve_exact, and shrink_to_fit.
The Str conveniences are forwarded so you don't write s.as_str().starts_with(...) everywhere: starts_with, ends_with, find, contains, trim, trim_start, trim_end, to_ascii_uppercase, to_ascii_lowercase, split, chars, and char_indices. Everything they return borrows this string's buffer and is valid only while it lives unmutated.
Crossing into C
A String built by push carries no trailing NUL, so as_ptr() alone is not a valid C string. Two methods bridge the gap:
as_cstr(mut &this) -> u8*borrows the buffer as a NUL-terminated C string. It writes the terminator at indexlength— reserving one spare byte if the buffer is full — without changing the logical length. Idempotent and zero-allocation once the spare byte exists. The pointer is valid until the next mutating call and must not be freed by the caller.into_raw(mut this) -> stringconsumes the string, appends a terminator, and hands back the raw buffer, leaking the allocation so the caller owns the bytes outright.
As in C, an interior NUL ends the string early; the bytes are not otherwise validated.
Trait implementations
implement<A> trait Eq for struct String<A> where A: Allocator
implement<A> trait Hash for struct String<A> where A: Allocator
implement<A> trait Ord for struct String<A> where A: Allocator
implement<A> trait Drop for struct String<A> where A: Allocator
implement trait Clone for struct String<GlobalAlloc>
implement trait Default for struct String<GlobalAlloc>
implement<A> trait Display for struct String<A> where A: Allocator
std::fmt::display
implement trait Debug for struct String<GlobalAlloc>
std::fmt::display
implement trait FmtWrite for struct String<GlobalAlloc>
std::fmt::write
Eq, Ord, and Hash agree with Str's, so a String and a Str holding the same bytes hash and compare identically. FmtWrite is what lets a String be the sink of a Formatter — format_to_string is built on it.
Constants
const INITIAL_CAPACITY: u64 = 8;type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
type parameter Atype struct GlobalAlloc {}Zero-sized handle to the process-wide allocator. Construct with GlobalAlloc::new(); all instances dispatch through the same underlying backend.
String.buffer: RawBuffer<u8, A>type struct RawBuffer<T, A = GlobalAlloc> where A: Allocator {
ptr: T*;
capacity: u64;
alloc: A;
}RawBuffer: the allocator-backed storage half of a growable container.
std::collections::raw_buffertype parameter AString.length: u64static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static String::new() -> StringEmpty string. No heap storage until the first push_* / reserve.
type struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
std::collections::stringstatic String::new_in(alloc: A) -> String<A>(parameter) alloc: Astatic String::with_capacity(capacity: u64) -> StringPreallocate room for capacity bytes. Panics on allocation failure.
(parameter) capacity: u64static String::try_with_capacity_in(capacity: u64, alloc: A) -> Result<String<A>, AllocError>type struct AllocError {
kind: AllocErrorKind;
layout: Layout;
}static String::from_str(source: Str) -> StringConstruct from a Str by copying its bytes. Panics on allocation failure.
(parameter) source: Strtype struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strstatic String::from_string(text: string) -> StringConstruct an owned String from a string (Cryo's raw NUL-terminated C-string view) by copying its bytes. Marked ![implicit]: the compiler treats this as the constructor when a string flows into a String slot - a parameter (println("text")) or a typed binding (mut s: String = "text").
(parameter) text: stringprimitive stringNUL-terminated raw string (u8*), matching the C ABI. Length-typed text is Str / String.
static String::with_null(source: Str) -> StringConstruct a NUL-terminated copy of source for handing to C. The terminating NUL lives in the buffer (so as_ptr() yields a valid const char*) but is excluded from the logical length, so as_str() / length() see only source. Matches C semantics on an interior NUL: the C side stops reading at the first one.
// reservedA reserved keyword with no syntax of its own in the current grammar. The standard library uses it freely as a method and parameter name (Str::from, from: u64).
String.item: TString::push<T>(mut &this, item: T) -> voidAppend item to the string as its **text** representation, dispatched at compile time via static match (T) - no runtime cost, no trait bound, because the available arms ARE the accepted types: - Str / string - the view's / C string's UTF-8 bytes verbatim (a string's terminating NUL is not copied).
type parameter Tmut &this
mut &TypeAn exclusive, mutating borrow. As a receiver, mut &this lets the method modify the fields - and callers can see that from the signature alone. As a parameter type, mut &T lets the callee mutate through the reference while the caller keeps ownership.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
(parameter) item: Ttype parameter TString::try_push<T>(mut &this, item: T) -> Result<(), AllocError>Fallible push: returns AllocError instead of panicking. Same compile-time dispatch as push.
type parameter Tprimitive ()The unit type: a value that carries no information, and the empty tuple. Distinct from void, which is the absence of a value - Result<(), E> succeeds with nothing to return. 0 bytes.
String::push_byte(mut &this, byte: u8) -> voidAppend a single **raw** byte (not its decimal text). For byte-exact work: NUL terminators, control characters, binary buffers. The caller is responsible for keeping the string valid UTF-8. Panics on allocation failure; use try_push_byte for the fallible form.
(parameter) byte: u8String::try_push_byte(mut &this, byte: u8) -> Result<(), AllocError>Fallible push_byte: append one raw byte, returning AllocError instead of panicking.
String::clear(mut &this) -> voidString::capacity(&this) -> u64String::is_empty(&this) -> booleanString::as_str(&this) -> StrBorrow as a Str. Invalidated by the next mutating call.
String::as_bytes(&this) -> Slice<u8>type struct Slice<T> {
ptr: T*;
length: u64;
}Slice<T>: a borrowed view into a contiguous sequence.
std::core::sliceString::as_ptr(&this) -> u8*String::as_cstr(mut &this) -> u8*Borrow this String as a NUL-terminated C string (u8* / const char*) for handing to an extern "C" API.
String::into_raw(mut this) -> stringConsume the String and return its NUL-terminated buffer as a raw string (C-string view), leaking the allocation so the caller owns the bytes with no borrow lifetime. A NUL terminator is appended first. The owning companion of Str::sub_bytes etc. for handing an owned C-string across the FFI / raw-string boundary.
mut thisA by-value receiver the body may also reassign. The receiver is moved into the method and consumed; the caller's value may not be used afterwards.
language referenceString::starts_with(&this, prefix: &Str) -> boolean(parameter) prefix: &StrString::ends_with(&this, suffix: &Str) -> boolean(parameter) suffix: &StrString::find(&this, needle: &Str) -> Option<u64>(parameter) needle: &StrString::contains(&this, needle: &Str) -> booleanString::trim(&this) -> StrBorrowed sub-slice with surrounding ASCII whitespace removed.
String::trim_start(&this) -> StrBorrowed sub-slice with leading ASCII whitespace removed. Mirrors Str::trim_start, closing the String vs Str method asymmetry.
String::trim_end(&this) -> StrBorrowed sub-slice with trailing ASCII whitespace removed. Mirrors Str::trim_end.
String::to_ascii_uppercase(&this) -> StringString::to_ascii_lowercase(&this) -> StringFresh String with every ASCII uppercase byte folded to lowercase. Mirrors Str::to_ascii_lowercase and the existing String::to_ascii_uppercase.
String::split(&this, sep: &Str) -> SplitIterIterator over pieces separated by sep (borrows this String).
(parameter) sep: &Strtype struct SplitIter {
bytes: u8*;
length: u64;
sep_bytes: u8*;
sep_length: u64;
pos: u64;
done: boolean;
}Lazy iterator over the pieces of a Str separated by a byte sequence. Yields borrowed Str views; see Str::split. Borrows from the source Str, which must outlive the iterator.
String::chars(&this) -> CharsIterator over Unicode scalar values (u32), decoding UTF-8 on the fly. Borrows this String; see Str::chars.
type struct Chars {
bytes: u8*;
length: u64;
pos: u64;
}Lazy UTF-8 scalar iterator over a Str; see Str::chars. Borrows from the source Str, which must outlive the iterator.
String::char_indices(&this) -> CharIndicesIterator over (byte_offset, scalar) pairs. Borrows this String; see Str::char_indices.
type struct CharIndices {
bytes: u8*;
length: u64;
pos: u64;
}Lazy (byte_offset, scalar) iterator over a Str; see Str::char_indices. Borrows from the source Str. Public for the same cross-module reason as Chars.
String::truncate(mut &this, new_length: u64) -> voidShrink length to new_length. No reallocation; capacity is unchanged. Bytes beyond new_length are no longer considered part of the string; subsequent push_* calls will overwrite them.
(parameter) new_length: u64String::reserve(mut &this, additional: u64) -> Result<(), AllocError>(parameter) additional: u64String::reserve_exact(mut &this, additional: u64) -> Result<(), AllocError>String::shrink_to_fit(mut &this) -> voidmut name: Type = value;A mutable binding, reassignable after declaration - mutability is opt-in, const is the default. At module level it declares mutable global state. Before & it marks an exclusive reference or receiver instead.
mut s: Stringstatic String::new() -> StringEmpty string. No heap storage until the first push_* / reserve.
mut s: StringString::push<T>(mut &this, item: T) -> voidAppend item to the string as its **text** representation, dispatched at compile time via static match (T) - no runtime cost, no trait bound, because the available arms ARE the accepted types: - Str / string - the view's / C string's UTF-8 bytes verbatim (a string's terminating NUL is not copied).
String::push_byte(mut &this, byte: u8) -> voidAppend a single **raw** byte (not its decimal text). For byte-exact work: NUL terminators, control characters, binary buffers. The caller is responsible for keeping the string valid UTF-8. Panics on allocation failure; use try_push_byte for the fallible form.
const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
const INITIAL_CAPACITY: u64 = 8;import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
String.buffer: RawBuffer<u8, A>String.length: u64String::reserve(mut &this, additional: u64) -> Result<(), AllocError>static String::new_in(alloc: A) -> String<A>static String::with_capacity(capacity: u64) -> StringPreallocate room for capacity bytes. Panics on allocation failure.
String::capacity(&this) -> u64static String::try_with_capacity_in(capacity: u64, alloc: A) -> Result<String<A>, AllocError>static String::from_str(source: Str) -> StringConstruct from a Str by copying its bytes. Panics on allocation failure.
static String::from_string(text: string) -> StringConstruct an owned String from a string (Cryo's raw NUL-terminated C-string view) by copying its bytes. Marked ![implicit]: the compiler treats this as the constructor when a string flows into a String slot - a parameter (println("text")) or a typed binding (mut s: String = "text").
static String::with_null(source: Str) -> StringConstruct a NUL-terminated copy of source for handing to C. The terminating NUL lives in the buffer (so as_ptr() yields a valid const char*) but is excluded from the logical length, so as_str() / length() see only source. Matches C semantics on an interior NUL: the C side stops reading at the first one.
String::as_ptr(&this) -> u8*const charString::as_str(&this) -> StrBorrow as a Str. Invalidated by the next mutating call.
String::as_cstr(mut &this) -> u8*Borrow this String as a NUL-terminated C string (u8* / const char*) for handing to an extern "C" API.
static match (T) { ... }Opens a compile-time match on a type parameter: the one arm whose type matches is kept during monomorphisation and the rest are discarded.
static match (T) {
u8 | u16 => { ... }
_ => { ... }
}Selects a body by inspecting a type parameter at compile time. The subject is a type and each arm is a type (| groups several; _ takes the rest). During monomorphisation the one matching arm is kept and the others discarded, so there is no runtime branch.
static String::from<T>(item: T) -> StringCreate a String from item, using the SAME compile-time static match (T) dispatch as push - the central T-generic constructor. String::from("hi"), String::from(65 as u32), String::from(true), String::from(some_str) all route through push. Panics on allocation failure.
value as TypeExplicit conversion: between numeric types, or reinterpreting one pointer type as another. Cryo never converts implicitly, and as inserts no range checks - a narrowing cast is the programmer's responsibility.
trueThe boolean literal. Booleans are a distinct 1-byte type, not interchangeable with integers; if and while conditions must be boolean.
type trait Display {
fmt<W>(&this, f: mut &Formatter<W>) -> Result<(), FmtError>
where W: FmtWrite;
}Display / Debug / Formatter.
std::fmt::displayprimitive usizePointer-width unsigned integer; the natural type for sizes and indices.
primitive typeString::try_push<T>(mut &this, item: T) -> Result<(), AllocError>Fallible push: returns AllocError instead of panicking. Same compile-time dispatch as push.
String::try_push_byte(mut &this, byte: u8) -> Result<(), AllocError>Fallible push_byte: append one raw byte, returning AllocError instead of panicking.
String::clear(mut &this) -> voidString::is_empty(&this) -> booleanString::as_bytes(&this) -> Slice<u8>extern function exit(code: i32) -> void;
extern "C" {
function puts(s: string) -> i32;
}Declares a function whose body the linker supplies - typically a C library symbol. The compiler trusts the Cryo signature; keeping it in step with the real C signature is on you.
language referenceString::into_raw(mut this) -> stringConsume the String and return its NUL-terminated buffer as a raw string (C-string view), leaking the allocation so the caller owns the bytes with no borrow lifetime. A NUL terminator is appended first. The owning companion of Str::sub_bytes etc. for handing an owned C-string across the FFI / raw-string boundary.
Str::sub_bytes(&this, start: u64, end: u64) -> Str[start, end) byte sub-slice. Panics if the range is out of bounds or if start > end. **Not UTF-8-aware**; splitting inside a multi-byte scalar is the caller's responsibility.
String::starts_with(&this, prefix: &Str) -> booleanString::ends_with(&this, suffix: &Str) -> booleanString::find(&this, needle: &Str) -> Option<u64>String::contains(&this, needle: &Str) -> booleanString::trim(&this) -> StrBorrowed sub-slice with surrounding ASCII whitespace removed.
std::collections::stringString::trim_start(&this) -> StrBorrowed sub-slice with leading ASCII whitespace removed. Mirrors Str::trim_start, closing the String vs Str method asymmetry.
Str::trim_start(&this) -> StrBorrowed sub-slice with leading ASCII whitespace removed.
std::collections::strString::trim_end(&this) -> StrBorrowed sub-slice with trailing ASCII whitespace removed. Mirrors Str::trim_end.
Str::trim_end(&this) -> StrBorrowed sub-slice with trailing ASCII whitespace removed.
std::collections::strString::to_ascii_uppercase(&this) -> StringString::to_ascii_lowercase(&this) -> StringFresh String with every ASCII uppercase byte folded to lowercase. Mirrors Str::to_ascii_lowercase and the existing String::to_ascii_uppercase.
Str::to_ascii_lowercase(&this) -> StringReturn a new String with every ASCII uppercase byte folded to lowercase. Non-ASCII bytes are passed through unchanged. Requires collections::string; callers that only need Str can byte-scan manually, but most callers want this method.
String::split(&this, sep: &Str) -> SplitIterIterator over pieces separated by sep (borrows this String).
String::chars(&this) -> CharsIterator over Unicode scalar values (u32), decoding UTF-8 on the fly. Borrows this String; see Str::chars.
Str::chars(&this) -> implement Iterator<u32>Iterator over the Unicode scalar values of this string, decoding UTF-8 on the fly. Each scalar is yielded as a u32 in the range [0, 0x10FFFF] (Cryo's char is a single byte, so a full scalar is a u32, not a char). This is the scalar-level counterpart to byte_at/as_bytes, which stay byte-level.
String::char_indices(&this) -> CharIndicesIterator over (byte_offset, scalar) pairs. Borrows this String; see Str::char_indices.
Str::char_indices(&this) -> implement Iterator<Pair<u64, u32>>Iterator over (byte_offset, scalar) pairs: the same scalars as chars, each paired with the byte index at which it begins. The pair is Pair<u64, u32> (p.first is the byte offset, p.second the scalar). Byte offsets are into this view's bytes, so a four-byte scalar advances the next offset by four.
String::truncate(mut &this, new_length: u64) -> voidShrink length to new_length. No reallocation; capacity is unchanged. Bytes beyond new_length are no longer considered part of the string; subsequent push_* calls will overwrite them.
String::reserve_exact(mut &this, additional: u64) -> Result<(), AllocError>String::shrink_to_fit(mut &this) -> voidnew T { field: value }
new E::Variant(args)
new T[n]Heap allocation. new T { .. } places a struct literal on the heap and yields a T*, and new E::V(args) does the same for an enum variant; new T[n] reserves n uninitialised T - the typed malloc. The storage comes from T's Allocate implementation, or else the global allocator. Parentheses after a struct's name are refused (E0117): there are no constructors, and a struct's static new(..) is an ordinary method.
function name(count: i32, args...)A variadic parameter: the trailing bucket receives any number of further arguments with C's calling convention, so the function stays ABI-compatible with the printf family. Wrap the bucket in VaArgs to read typed values from it.
implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
type parameter Awhere A: Allocator
type trait Name : Base {
method(&this, other: &This) -> Ret;
}Names a set of methods a type may implement. Inside the body This is the implementing type; methods may carry default bodies, and a trait may require a base trait (type trait Ord : Eq). Generic code asks for a trait with where T: Name.
type trait Eq {
equals(&this, other: &This) -> boolean;
}Types that support value equality. equals(a, b) must be reflexive, symmetric, and transitive.
implement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencewhere T: Ord + Clone, U: HashConstrains generic parameters to types that implement the listed traits, which is what makes those traits' methods callable on T. Bounds on one parameter join with +; parameters separate with ,. A where on a single method narrows the type's parameter for that method only.
type trait Allocator {
allocate(mut &this, layout: Layout) -> Result<NonNull<u8>, AllocError>;
deallocate(mut &this, ptr: NonNull<u8>, layout: Layout) -> void;
reallocate(mut &this, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout) -> Result<NonNull<u8>, AllocError>;
}Allocator: the trait every heap strategy implements.
std::alloc::allocatortype trait Ord : Eq {
compare(&this, other: &This) -> Ordering;
}Types that have a total order: every pair is Less, Equal, or Greater. compare must be consistent with equals: if a.equals(b) then a.compare(b) == Equal.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referencetype trait Default {
static default() -> This;
}Default: a canonical "zero value" for a type.
std::core::defaulttype trait Debug {
fmt<W>(&this, f: mut &Formatter<W>) -> Result<(), FmtError>
where W: FmtWrite;
}type trait FmtWrite {
write_str(mut &this, source: Str) -> Result<(), FmtError>;
write_char(mut &this, c: char) -> Result<(), FmtError>;
}