MCPcopy Index your code
hub / github.com/carllerche/assert-struct / error_label

Function error_label

assert-struct/src/error.rs:275–314  ·  view source on GitHub ↗

Build a human-readable annotation label for a failed assertion.

(error: &ErrorContext)

Source from the content-addressed store, hash-verified

273
274/// Build a human-readable annotation label for a failed assertion.
275fn error_label(error: &ErrorContext) -> String {
276 match &error.error_node.kind {
277 NodeKind::Comparison {
278 op: ComparisonOp::Equal,
279 ..
280 } => format!(
281 "expected {}, got {}",
282 error.expected_value.as_deref().unwrap_or("?"),
283 error.actual_value,
284 ),
285 NodeKind::EnumVariant { .. } => format!(
286 "expected variant {}, got {}",
287 error.error_node, error.actual_value,
288 ),
289 NodeKind::Slice { items, rest } => {
290 if *rest {
291 format!("slice pattern mismatch, got {}", error.actual_value)
292 } else {
293 let n = items.len();
294 let suffix = if n == 1 { "element" } else { "elements" };
295 format!(
296 "expected slice with {} {}, got {}",
297 n, suffix, error.actual_value
298 )
299 }
300 }
301 NodeKind::Set { rest, .. } => {
302 if *rest {
303 format!("set pattern mismatch, got {}", error.actual_value)
304 } else {
305 format!("set pattern mismatch (exact), got {}", error.actual_value)
306 }
307 }
308 NodeKind::Closure { .. } => format!(
309 "closure condition not satisfied, got {}",
310 error.actual_value,
311 ),
312 _ => format!("got {}", error.actual_value),
313 }
314}
315
316impl fmt::Display for ErrorReport {
317 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

Callers

nothing calls this directly

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected