From 77aa501498978e0e1af046dad093dca65404f76b Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 31 Jan 2026 13:08:20 +0100 Subject: [PATCH] std-traits: add explanatory commentary to solution This commentary, written by Gemini, focuses on aspects of the solution that differ from the baseline languages (C/Java/Python), highlighting Rust-specific idioms and concepts. --- src/std-traits/solution.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/std-traits/solution.md b/src/std-traits/solution.md index b4a4c92cd998..a47a2c412645 100644 --- a/src/std-traits/solution.md +++ b/src/std-traits/solution.md @@ -3,3 +3,21 @@ ```rust,editable {{#include exercise.rs:solution}} ``` + +- **Wrapper Pattern:** `RotDecoder` wraps another reader `R`. +- **Delegation:** The `read` implementation first calls `self.input.read(buf)` + to read data into the buffer. This is essential; we need raw data before we + can transform it. +- **In-place Mutation:** After reading, the code iterates over the populated + part of the buffer (`buf[..size]`) and modifies the bytes in place. +- **Error Handling:** The `?` operator is used to check the result of + `self.input.read`. If it fails, the error is immediately returned. + +
+ +- Mention that `rot` is a simple Caesar cipher. +- Chaining two ROT13 instances (rotations by 13) results in a rotation by 26, + which wraps around to the original text (for English alphabets). This property + is why ROT13 is its own inverse. + +