Update book

This commit is contained in:
Andrzej Głuszak 2022-08-23 23:33:14 +02:00
parent 43cd95fe47
commit e3f09fa122

View file

@ -18,23 +18,7 @@ eprintln!("Expression = {:?}", expr.debug(db));
and get back the output you expect.
## Implementing the `DebugWithDb` trait
For now, unfortunately, you have to implement the `DebugWithDb` trait manually, as we do not provide a derive.
This is tedious but not difficult. Here is an example of implementing the trait for `Expression`:
```rust
{{#include ../../../calc-example/calc/src/ir.rs:expression_debug_impl}}
```
Some things to note:
- The `data` method gives access to the full enum from the database.
- The [`Formatter`] methods (e.g., [`debug_tuple`]) can be used to provide consistent output.
- When printing the value of a field, use `.field(&a.debug(db))` for fields that are themselves interned or entities, and use `.field(&a)` for fields that just implement the ordinary `Debug` trait.
[`debug_tuple`]: https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_tuple
[`formatter`]: https://doc.rust-lang.org/std/fmt/struct.Formatter.html#
The `DebugWithDb` trait is automatically derived for all `#[input]`, `#[interned]` and `#[tracked]` structs.
## Forwarding to the ordinary `Debug` trait