rustysan-sword 0.1.1

Blade-inspired HTML templates for Rust
Documentation
---
title: Dumping a value while developing
weight: 9
---

`@dump(value, ['field', ...])` prints a value in an escaped `<pre class="sword-dump">` so a template can be debugged without leaving the page. It is development tooling with several independent switches, all of which must be on:

- the `dump` Cargo feature, which is off by default and compiles the collector out of normal builds;
- `Config::builder().dump(true)` (or `SWORD_DUMP=1` with `Config::from_env()`; under Laravel, `SWORD_DUMP=true` or `SwordServiceProvider::new().dump(true)`, and the application refuses to boot if that is set outside `local` or `testing`);
- an environment of `local` or `testing`.

Otherwise `@dump(...)` renders nothing and its argument is not evaluated, so a forgotten `@dump(user.password)` in a production build neither shows nor reads the value. Enabling the feature through feature unification therefore changes nothing at runtime.

Redaction is by allowlist, at capture. Scalars and sequences show as they are; a map shows only the fields named in the second argument, applied at every depth, and the rest are counted as `… N fields not listed`, never named or shown:

```html
@dump(user, ['id', 'name'])
```

Output is bounded: six levels, 50 entries per list or map, 200 characters per string and 8 KiB in all. Values are never logged. `@dd` is a syntax error, because stopping a render halfway has no useful meaning with sections, fragments and stacks. For anything else use Rust debugging or `tracing`.