error
import std::random::error; · source
Types
RandomError
type enum RandomError {
;
EmptyRange;
InvalidWeights;
}
implement enum RandomError {
describe(&this) -> Str;
rank(&this) -> i32;
}
Every fallible call in the module — a bounded draw, a weighted table, the entropy source itself — reports one of these.
Variants
| Variant |
|---|
EntropyUnavailable |
EmptyRange |
InvalidWeights |
Methods
describe(&this) -> Str;
describe(&this) -> Str;A short, stable description of the failure, as a borrowed Str. The convergent accessor every stdlib error type exposes (describe(&this) -> Str); Display/Debug for RandomError delegate to it. Borrows a static string literal, so the view outlives any RandomError.
rank(&this) -> i32;
rank(&this) -> i32;Discriminant rank, for equality.
Trait implementations
implement trait Eq for enum RandomError
implement trait Display for enum RandomError
std::fmt::display
implement trait Debug for enum RandomError
std::fmt::display
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 enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum RandomError {
EntropyUnavailable;
EmptyRange;
InvalidWeights;
}What went wrong in a fallible random operation.
RandomError::EntropyUnavailableRandomError::EmptyRangeRandomError::InvalidWeightsimplement 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.
implement enum Name { ... }Names the enum an inherent block extends - the only way to give an enum methods.
language referencetype enum RandomError {
EntropyUnavailable;
EmptyRange;
InvalidWeights;
}What went wrong in a fallible random operation.
std::random::errorRandomError::describe(&this) -> StrA short, stable description of the failure, as a borrowed Str. The convergent accessor every stdlib error type exposes (describe(&this) -> Str); Display/Debug for RandomError delegate to it. Borrows a static string literal, so the view outlives any RandomError.
&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.
type struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strRandomError::rank(&this) -> i32Discriminant rank, for equality.
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).
RandomError::EntropyUnavailableRandomError::EmptyRangeRandomError::InvalidWeightsRandomError::describe(&this) -> StrA short, stable description of the failure, as a borrowed Str. The convergent accessor every stdlib error type exposes (describe(&this) -> Str); Display/Debug for RandomError delegate to it. Borrows a static string literal, so the view outlives any RandomError.
type trait Display {
fmt<W>(&this, f: mut &Formatter<W>) -> Result<(), FmtError>
where W: FmtWrite;
}Display / Debug / Formatter.
std::fmt::displaytype trait Debug {
fmt<W>(&this, f: mut &Formatter<W>) -> Result<(), FmtError>
where W: FmtWrite;
}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 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 reference