Skip to content

Commit

Permalink
Notes: fix incomplete sentence in latest! Doh!
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed Jan 31, 2025
1 parent 1837e62 commit 3e1a635
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ impl Serialize for Email {

Combined with an `impl` for `std::fmt::Display` to automatically get the `to_string()`, my problem was solved, and things started working as I had expect them to work in the first place!

Takeaway: because minijinja currently *serializes* and *deserializes* values to send them through its templating layer
Takeaway: because minijinja currently *serializes* and *deserializes* values to send them through its templating layer, they need to be able to “round trip” successfully to the data types you are using.

[^roughly]: That “(roughly-)” is there because actually validating emails is pretty tricky!

[^overkill]: This was “overkill”: I don’t actually take advantage of the split between `local` and `host` at all, and a much simpler “newtype” pattern would actually make more sense:

```rust
struct Email(String);

impl std::str::FromStr for EmaiI {
type Err = SomeErrorType;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// do whatever parsing work here
}
Expand All @@ -90,4 +90,4 @@ Takeaway: because minijinja currently *serializes* and *deserializes* values to

[pdv]: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/

[^could]: I *could* make that `Deserialize` implementation work with amap” as well so that it could work with this object, but I have no reason ever to serialize this particular `Email` as anything but a `String`.
[^could]: I *could* make that `Deserialize` implementation work with amap” as well so that it could work with this object, but I have no reason ever to serialize this particular `Email` as anything but a `String`.

0 comments on commit 3e1a635

Please sign in to comment.