error
import std::test::error; · source
Types
TestError
type enum TestError {
Failed(String);
Other(String);
}
implement enum TestError {
message_str(&this) -> Str;
static failed(message: Str) -> TestError;
static other(message: Str) -> TestError;
}
Failed is an assertion that did not hold; Other is everything else. It owns its message, so it carries a drop.
Variants
| Variant | Notes |
|---|---|
Failed(String) | A user assertion failed. Carries the assertion message. |
Other(String) | Any other reason a test could not produce a definitive result: I/O error during setup, environment problem, etc. |
Constructors
static failed(message: Str) -> TestError;
static failed(message: Str) -> TestError;Construct a Failed from a borrowed Str. Allocates an owned copy of the message; the test function's source string can safely outlive the resulting TestError value.
static other(message: Str) -> TestError;
static other(message: Str) -> TestError;Construct an Other from a borrowed Str. Allocates an owned copy of the message.
Methods
message_str(&this) -> Str;
message_str(&this) -> Str;Borrowed view into the variant's message. Cheap: no allocation, no Drop interaction. Valid for the lifetime of the TestError. Use this when you only need to display or compare the message.
Trait implementations
implement trait Drop for enum TestError
implement trait Display for enum TestError
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 TestError {
Failed(String);
Other(String);
}Why a test failed. The runner prints the variant's message verbatim to stderr from the child process before exiting non-zero, so the parent can show the failing message in the test summary.
TestError::Failed(String)A user assertion failed. Carries the assertion message.
type struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
std::collections::stringTestError::Other(String)Any other reason a test could not produce a definitive result: I/O error during setup, environment problem, etc.
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.
implement enum Name { ... }Names the enum an inherent block extends - the only way to give an enum methods.
language referencetype enum TestError {
Failed(String);
Other(String);
}Why a test failed. The runner prints the variant's message verbatim to stderr from the child process before exiting non-zero, so the parent can show the failing message in the test summary.
std::test::errorTestError::message_str(&this) -> StrBorrowed view into the variant's message. Cheap: no allocation, no Drop interaction. Valid for the lifetime of the TestError. Use this when you only need to display or compare the message.
&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::strstatic 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 TestError::failed(message: Str) -> TestErrorConstruct a Failed from a borrowed Str. Allocates an owned copy of the message; the test function's source string can safely outlive the resulting TestError value.
(parameter) message: Strstatic TestError::other(message: Str) -> TestErrorConstruct an Other from a borrowed Str. Allocates an owned copy of the message.
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).
TestError::Other(String)Any other reason a test could not produce a definitive result: I/O error during setup, environment problem, etc.
std::test::errorstatic TestError::failed(message: Str) -> TestErrorConstruct a Failed from a borrowed Str. Allocates an owned copy of the message; the test function's source string can safely outlive the resulting TestError value.
static TestError::other(message: Str) -> TestErrorConstruct an Other from a borrowed Str. Allocates an owned copy of the message.
TestError::message_str(&this) -> StrBorrowed view into the variant's message. Cheap: no allocation, no Drop interaction. Valid for the lifetime of the TestError. Use this when you only need to display or compare the message.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referenceimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype trait Display {
fmt<W>(&this, f: mut &Formatter<W>) -> Result<(), FmtError>
where W: FmtWrite;
}Display / Debug / Formatter.
std::fmt::display