liveBook · Manning

Assert_ne

As explained in Learn Rust in a Month of Lunches

assert_ne! is a Rust macro that panics when two values are equal.

assert_ne! checks that two values are different. If they are equal, the program panics. The ne means “not equal,” making the macro useful for catching logic errors and testing assumptions. section 6.3

Checking an input

let my_name = "Loki Laufeyson"; assert_ne!(my_name, "Mithridates"); This assertion succeeds because the two values differ. If my_name is "Mithridates", assert_ne! panics instead.

How Learn Rust in a Month of Lunches covers it

How deep it goes
Defines the comparison rule, failure behavior, and custom messages, but does not detail macro expansion internals.
Examples
Uses string comparisons for successful assertions, custom messages, and a failing Mithridates input.
What it assumes
Assumes basic Rust values and comparisons while defining assertion macros and panic behavior directly.
What you can do after
Apply it via Rust syntax to verify that two values differ and produce a useful panic message when they do not.
How it connects
Connects assert_ne! with panic!, assert!, and assert_eq! as related assertion and failure macros.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.