assertables

Macro assert_starts_with

Source
macro_rules! assert_starts_with {
    ($whole:expr, $part:expr $(,)?) => { ... };
    ($whole:expr, $part:expr, $($message:tt)+) => { ... };
}
Expand description

Assert an expression (such as a string) starts with an expression (such as a string).

Pseudocode:
a.starts_with(b)

  • If true, return ().

  • Otherwise, call panic! with a message and the values of the expressions with their debug representations.

§Examples

use assertables::*;

// String starts with substring?
let whole: &str = "alfa";
let part: &str = "al";
assert_starts_with!(whole, part);

// Vector starts with element?
let whole = vec![1, 2, 3];
let part = [1];
assert_starts_with!(whole, part);

// This will panic
let whole = "alfa";
let part = "fa";
assert_starts_with!(whole, part);
// assertion failed: `assert_starts_with!(whole, part)`
// https://docs.rs/assertables/9.1.0/assertables/macro.assert_starts_with.html
//  whole label: `whole`,
//  whole debug: `\"alfa\"`,
//   part label: `part`,
//   part debug: `\"fa\"`

§Module macros