prelude library
rust_core comes with a variety of things in its core library. However, if you had to manually import every single thing that you used, it would be very verbose. But importing a lot of things that a program never uses isn’t good either. A balance needs to be struck. The prelude is the list of things that rust_core should automatically imports into almost all projects. It’s kept as small as possible, and is focused on things, which are used in almost every single rust_core program.
Classes
-
ArrayChunksRIterator<
T> -
Returns an iterator over N elements of the iterator at a time.
The chunks do not overlap. If N does not divide the length of the iterator, then the last up to N-1 elements will
be omitted and can be retrieved from the
.intoRemainder()
function of the iterator. -
CastRIterator<
S, T> -
ChainRIterator<
T> - Takes two iterators and creates a new iterator over both in sequence.
-
CloneRIterator<
T> - An iterator which is a "clone" of the original iterator. Iterating through the original or the clone will not affect the other. Note: Do not modify the original collection the original Iterable is based on while iterating. Explanation: Since Dart Iterators cannot be copied, CloneRIterator replaces the underlying iterator from the RIterator provided in the constructor with itself and collects any first calls to moveNext from any derived iterator. Due to this, modifications of the original iterable may have unintentional behavior on the cloned iterator. i.e. the first encounter of an object during iteration will be the one seen by the derived RIterator and all other subsequent CloneRIterators. Therefore if createing a CloneRIterator do not modify the original collection the passed in RIterator is based on.
-
CycleRIterator<
T> - Creates an iterator which repeats the elements of the original iterator endlessly.
-
Err<
S, F extends Object> - Error Result.
-
FlatMapRIterator<
S, T> - Maps each element of the original iterator to an iterator, and then flattens the result into a single iterator.
-
Ok<
S, F extends Object> - Ok Result.
-
PeekableRIterator<
T> - An iterator which can use the "peek" to look at the next element of the iterator without consuming it.
-
Result<
S, F extends Object> - Result class representing the type union between Ok and Err.
-
RIterator<
T> - RIterator is the union between an Iterator and an Iterable. Most iterator methods are consuming and should be assumed to be so unless otherwise stated.
-
Slice<
T> - A contiguous sequence of elements in a List. Slices are a view into a list without allocating and copying to a new list, as such, they do not own their own data. Note: Shrinking the original list can cause the slices range to become invalid, which may cause an exception.
-
SliceIterator<
T> - An iterator over the elements of a Slice.
-
ZipRIterator<
T, U> - Zips to iterators into a single iterator of pairs.
Extension Types
- Arr
-
A fixed-size array, denoted as
T; N
in Rust. - Option
-
Option represents the union of two types -
Some<T>
andNone
. As an extension type ofT?
,Option<T>
has the same runtime cost ofT?
with the advantage of being able to chain null specific operations. - Some
-
Represents a value that is present. The erasure of this is
T
.
Extensions
-
ArrayOnIterableExtension
on Iterable<
T> -
ArrayOnListExtension
on List<
T> -
FlattenExtension
on Result<
Result< S, F> , F> -
FlattenFutureExtension
on FutureResult<
Result< S, F> , F> -
FutureIterableFutureResultExtensions
on Future<
Iterable< FutureResult< >S, F> > -
FutureIterableResultExtensions
on Future<
Iterable< Result< >S, F> > -
FutureOptionExtension
on FutureOption<
T> - FutureOption represents an asynchronous Option. And as such, inherits all of Option's methods.
-
FutureOptionOptionExtension
on FutureOption<
Option< T> > -
FutureOptionRecord2Extension
on FutureOption<
(T, U)> -
FutureOptionResultExtension
on FutureOption<
Result< S?, F> > -
FutureResultExtension
on FutureResult<
S, F> - FutureResult represents an asynchronous Result. And as such, inherits all of Results methods.
-
FutureResultNullExtension
on Future<
Result< S?, F> > -
FutureResultOptionExtension
on Future<
Result< Option< >S?> , F> -
FutureToOption
on Future<
T?> -
InfallibleErrExtension
on Result<
Never, F> -
InfallibleFutureErrExtension
on FutureResult<
Never, F> -
InfallibleFutureOkExtension
on FutureResult<
S, Never> -
InfallibleOkExtension
on Result<
S, Never> -
IterableExtension
on Iterable<
T> -
IterableExtensionsOverrides
on RIterator<
T> - Overrides built in extension methods on Iterable.
-
IterableFutureResultExtensions
on Iterable<
FutureResult< S, F> > -
IterableResultExtensions
on Iterable<
Result< S, F> > -
IteratorComparable
on RIterator<
T> -
IteratorComparableSelf
on RIterator<
T> -
IteratorExtension
on Iterator<
T> -
IteratorOnIteratorIterabel
on RIterator<
Iterable< T> > -
IteratorOnIteratorTUExtension
on RIterator<
(T, U)> -
IteratorOptionExtension
on RIterator<
Option< T> > -
IteratorResultExtension
on RIterator<
Result< T, E> > -
IteratorResultFuncExtension
on RIterator<
T> - NoneMethodsExtension on _None
-
NullableIterableExtensionsOverrides
on RIterator<
T?> - Overrides built in extension methods on nullable Iterable.
-
NullResultExtension
on Result<
S, F> ? -
OptionMethodsExtension
on Option<
T> -
OptionNullableExtension
on Option<
T?> -
OptionOptionExtension
on Option<
Option< T> > -
OptionRecord2Extension
on Option<
(T, U)> -
OptionResultExtension
on Option<
Result< S?, F> > -
OptionToFutureOption
on Option<
T> -
RecordFunctionToResult10
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function(), Result<D, Z> Function(), Result<E, Z> Function(), Result<F, Z> Function(), Result<G, Z> Function(), Result<H, Z> Function(), Result<I, Z> Function(), Result<J, Z> Function()) -
RecordFunctionToResult2
on (Result<
A, Z> Function(), Result<B, Z> Function()) -
RecordFunctionToResult3
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function()) -
RecordFunctionToResult4
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function(), Result<D, Z> Function()) -
RecordFunctionToResult5
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function(), Result<D, Z> Function(), Result<E, Z> Function()) -
RecordFunctionToResult6
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function(), Result<D, Z> Function(), Result<E, Z> Function(), Result<F, Z> Function()) -
RecordFunctionToResult7
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function(), Result<D, Z> Function(), Result<E, Z> Function(), Result<F, Z> Function(), Result<G, Z> Function()) -
RecordFunctionToResult8
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function(), Result<D, Z> Function(), Result<E, Z> Function(), Result<F, Z> Function(), Result<G, Z> Function(), Result<H, Z> Function()) -
RecordFunctionToResult9
on (Result<
A, Z> Function(), Result<B, Z> Function(), Result<C, Z> Function(), Result<D, Z> Function(), Result<E, Z> Function(), Result<F, Z> Function(), Result<G, Z> Function(), Result<H, Z> Function(), Result<I, Z> Function()) -
RecordToResult10
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> , Result<D, Z> , Result<E, Z> , Result<F, Z> , Result<G, Z> , Result<H, Z> , Result<I, Z> , Result<J, Z> ) -
RecordToResult2
on (Result<
A, Z> , Result<B, Z> ) -
RecordToResult3
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> ) -
RecordToResult4
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> , Result<D, Z> ) -
RecordToResult5
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> , Result<D, Z> , Result<E, Z> ) -
RecordToResult6
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> , Result<D, Z> , Result<E, Z> , Result<F, Z> ) -
RecordToResult7
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> , Result<D, Z> , Result<E, Z> , Result<F, Z> , Result<G, Z> ) -
RecordToResult8
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> , Result<D, Z> , Result<E, Z> , Result<F, Z> , Result<G, Z> , Result<H, Z> ) -
RecordToResult9
on (Result<
A, Z> , Result<B, Z> , Result<C, Z> , Result<D, Z> , Result<E, Z> , Result<F, Z> , Result<G, Z> , Result<H, Z> , Result<I, Z> ) -
ResultFutureToFutureResultExtension
on Result<
Future< S> , F> -
ResultNullExtension
on Result<
S?, F> -
ResultOptionExtension
on Result<
Option< S?> , F> -
ResultToFutureResultExtension
on Result<
S, F> -
SliceOnComparableSliceExtension
on Slice<
T> -
SliceOnListExtension
on List<
T> -
SliceOnSliceIntExtension
on Slice<
T> -
SomeMethodsExtension
on Some<
T> - ToErrExtension on E
- ToOkExtension on S
Constants
Functions
-
executeProtected<
S> (S func()) → Result< S, Object> -
Executes the function in a protected context.
func
is called inside a try catch block. If the result is not catch, then return valuefunc
returned inside an Ok. Iffunc
throws, then the thrown value is returned inside an Err. -
executeProtectedAsync<
S> (Future< S> func()) → FutureResult<S, Object> - Async version of executeProtected
-
executeProtectedAsyncResult<
S> (Future< Result< func()) → FutureResult<S, Object> >S, Object> - Async version of executeProtectedResult
-
executeProtectedResult<
S> (Result< S, Object> func()) → Result<S, Object> -
Result unwrapping version of executeProtected. Where
func
returns an Result, but can still throw. -
panic(
[String? msg]) → Never - Shorthand for
-
unreachable(
[String msg = "This code should be unreachable."]) → Never - Shorthand for
Typedefs
-
FutureOption<
T> = Future< Option< T> > - FutureOption represents an asynchronous Option. And as such, inherits all of Option's methods.
-
FutureResult<
S, F extends Object> = Future< Result< S, F> > - FutureResult represents an asynchronous Result. And as such, inherits all of Results methods.
- Infallible = Never
- The error type for errors that can never happen
- Unit = ()
- Type alias for (). Used for a Result when the returned value does not matter. Preferred over void since forces stricter types. See unit, okay, and error
Exceptions / Errors
- GetManyError
- GetManyErrorRequestedIndexOutOfBounds
- GetManyErrorTooManyIndices
- Panic
-
As with Error, Panic represents a state that should never happen and thus is not expected to be catch.
This is closely tied to the
unwrap
method of both Option and Result types. - Unreachable
- Indicates unreachable code. This is useful any time that the compiler can’t determine that some code is unreachable. For example: