Expand description
§const it!
This crate provides some utilities for use in const evaluation contexts, in particular const slicing and error handling.
The slice! and try_slice! macros slice (using any usize or range expression):
const STR: &str = slice!("const slice", ..5); // "const"The split_slice_at! and try_split_slice_at! macros split a slice in two:
const STR: (&str, &str) = split_slice_at!("const slice", 5); // ("const", " slice")The ok!, expect_ok!, unwrap_ok!, unwrap_ok_or_return!, expect_some!, unwrap_some!
and unwrap_some_or_return! macros work with Results and Options.
Macros§
- Takes a
Resultand returns the unwrappedOkvalue, or panics if it’sErr. The second argument is the message to use on panic. If the panic message is omitted, theErrvalue must be of type&strand is used as the panic message. - Takes an
Optionand returns the unwrappedSomevalue, or panics if it’sNone. The second argument is the message to use on panic. - Turn a
Resultinto anOption. - Slice an item in a const context. The first argument is the item to slice, and the second is the slice index, which can be a usize or any usize range type. Panics if the index is out of range or, for strings, if the slice would split a unicode codepoint.
- Split a slice in two at the specified index. Panics on error.
- Slice an item in a const context. The first argument is the item to slice, and the second is the slice index, which can be a usize or any usize range type. Returns
Some(sliced), orNoneif the index is out of range or, for strings, if the slice would split a unicode codepoint. - Split a slice in two at the specified index. Returns
Noneon error. - Takes a
Resultand returns the unwrappedOkvalue, or panics if it’sErr. - Takes a
Resultand evaluates to the unwrappedOkvalue, or if it’sErr, returns theErrto the current function’s caller. - Takes an
Optionand returns the unwrappedSomevalue, or panics if it’sNone. - Takes an
Optionand evaluates to the unwrappedSomevalue, or if it’sNone, returns theNoneto the current function’s caller.
Structs§
- A pending slice operation. This can be used to slice
&[T]and&strin a const context with any valid slice index.
Traits§
- This trait is similar to the
SliceIndextrait in std/core, but it’s implemented for array types too.