From 30c421dba813f1266eeee734c34322db9c5f2b24 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 16 Sep 2023 17:18:40 +0200 Subject: [PATCH] Trim off licenses when showing solutions The licenses end up in the PO files, causing extra unnecessary for work our translators. We save about 300 lines from each PO file with this. This also solves another small problem: when a file is included with an anchor, other anchors are automatically stripped away. This removes some confusing `// ANCHOR: foo` and `// ANCHOR_END: foo` lines in the solutions. --- src/exercises/bare-metal/compass/src/main.rs | 1 + src/exercises/bare-metal/rtc/src/main.rs | 1 + src/exercises/bare-metal/rtc/src/pl031.rs | 1 + src/exercises/bare-metal/solutions-afternoon.md | 4 ++-- src/exercises/bare-metal/solutions-morning.md | 2 +- src/exercises/concurrency/chat-async/src/bin/client.rs | 1 + src/exercises/concurrency/chat-async/src/bin/server.rs | 1 + src/exercises/concurrency/dining-philosophers-async.rs | 1 + src/exercises/concurrency/dining-philosophers.rs | 1 + src/exercises/concurrency/link-checker.rs | 1 + src/exercises/concurrency/solutions-afternoon.md | 6 +++--- src/exercises/concurrency/solutions-morning.md | 4 ++-- src/exercises/day-1/for-loops.rs | 1 + src/exercises/day-1/luhn.rs | 1 + src/exercises/day-1/solutions-afternoon.md | 2 +- src/exercises/day-1/solutions-morning.md | 2 +- src/exercises/day-2/book-library.rs | 1 + src/exercises/day-2/solutions-afternoon.md | 2 +- src/exercises/day-2/solutions-morning.md | 2 +- src/exercises/day-2/strings-iterators.rs | 1 + src/exercises/day-3/points-polygons.rs | 1 + src/exercises/day-3/safe-ffi-wrapper.rs | 1 + src/exercises/day-3/simple-gui.rs | 1 + src/exercises/day-3/solutions-afternoon.md | 2 +- src/exercises/day-3/solutions-morning.md | 4 ++-- src/exercises/solutions.md | 5 ----- 26 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/exercises/bare-metal/compass/src/main.rs b/src/exercises/bare-metal/compass/src/main.rs index 854975c54777..31fc8645313d 100644 --- a/src/exercises/bare-metal/compass/src/main.rs +++ b/src/exercises/bare-metal/compass/src/main.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: top #![no_main] #![no_std] diff --git a/src/exercises/bare-metal/rtc/src/main.rs b/src/exercises/bare-metal/rtc/src/main.rs index d3ace2b29858..029868cf74f3 100644 --- a/src/exercises/bare-metal/rtc/src/main.rs +++ b/src/exercises/bare-metal/rtc/src/main.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: top #![no_main] #![no_std] diff --git a/src/exercises/bare-metal/rtc/src/pl031.rs b/src/exercises/bare-metal/rtc/src/pl031.rs index 426ea5334125..acd4f75d0dd0 100644 --- a/src/exercises/bare-metal/rtc/src/pl031.rs +++ b/src/exercises/bare-metal/rtc/src/pl031.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution use core::ptr::{addr_of, addr_of_mut}; #[repr(C, align(4))] diff --git a/src/exercises/bare-metal/solutions-afternoon.md b/src/exercises/bare-metal/solutions-afternoon.md index cc403ea01b05..6e8c420cc034 100644 --- a/src/exercises/bare-metal/solutions-afternoon.md +++ b/src/exercises/bare-metal/solutions-afternoon.md @@ -7,11 +7,11 @@ `main.rs`: ```rust,compile_fail -{{#include rtc/src/main.rs}} +{{#include rtc/src/main.rs:solution}} ``` `pl031.rs`: ```rust -{{#include rtc/src/pl031.rs}} +{{#include rtc/src/pl031.rs:solution}} ``` diff --git a/src/exercises/bare-metal/solutions-morning.md b/src/exercises/bare-metal/solutions-morning.md index f11e830fd98d..31b1e0282612 100644 --- a/src/exercises/bare-metal/solutions-morning.md +++ b/src/exercises/bare-metal/solutions-morning.md @@ -5,5 +5,5 @@ ([back to exercise](compass.md)) ```rust,compile_fail -{{#include compass/src/main.rs}} +{{#include compass/src/main.rs:solution}} ``` diff --git a/src/exercises/concurrency/chat-async/src/bin/client.rs b/src/exercises/concurrency/chat-async/src/bin/client.rs index 8817ba0b5fa0..bc912a28b376 100644 --- a/src/exercises/concurrency/chat-async/src/bin/client.rs +++ b/src/exercises/concurrency/chat-async/src/bin/client.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: setup use futures_util::stream::StreamExt; use futures_util::SinkExt; diff --git a/src/exercises/concurrency/chat-async/src/bin/server.rs b/src/exercises/concurrency/chat-async/src/bin/server.rs index 0b197547aab8..a707fbe1a216 100644 --- a/src/exercises/concurrency/chat-async/src/bin/server.rs +++ b/src/exercises/concurrency/chat-async/src/bin/server.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: setup use futures_util::sink::SinkExt; use futures_util::stream::StreamExt; diff --git a/src/exercises/concurrency/dining-philosophers-async.rs b/src/exercises/concurrency/dining-philosophers-async.rs index 4518e79b2e4c..b20bf62269a5 100644 --- a/src/exercises/concurrency/dining-philosophers-async.rs +++ b/src/exercises/concurrency/dining-philosophers-async.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: Philosopher use std::sync::Arc; use tokio::time; diff --git a/src/exercises/concurrency/dining-philosophers.rs b/src/exercises/concurrency/dining-philosophers.rs index d1ab7b8040e8..9e1ab8209797 100644 --- a/src/exercises/concurrency/dining-philosophers.rs +++ b/src/exercises/concurrency/dining-philosophers.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: Philosopher use std::sync::{mpsc, Arc, Mutex}; use std::thread; diff --git a/src/exercises/concurrency/link-checker.rs b/src/exercises/concurrency/link-checker.rs index 17ef60cfa91e..7f702c929153 100644 --- a/src/exercises/concurrency/link-checker.rs +++ b/src/exercises/concurrency/link-checker.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution use std::{sync::Arc, sync::Mutex, sync::mpsc, thread}; // ANCHOR: setup diff --git a/src/exercises/concurrency/solutions-afternoon.md b/src/exercises/concurrency/solutions-afternoon.md index 3ccf76b8911e..08cdc875f909 100644 --- a/src/exercises/concurrency/solutions-afternoon.md +++ b/src/exercises/concurrency/solutions-afternoon.md @@ -5,7 +5,7 @@ ([back to exercise](dining-philosophers-async.md)) ```rust,compile_fail -{{#include dining-philosophers-async.rs}} +{{#include dining-philosophers-async.rs:solution}} ``` ## Broadcast Chat Application @@ -15,12 +15,12 @@ `src/bin/server.rs`: ```rust,compile_fail -{{#include chat-async/src/bin/server.rs}} +{{#include chat-async/src/bin/server.rs:solution}} ``` `src/bin/client.rs`: ```rust,compile_fail -{{#include chat-async/src/bin/client.rs}} +{{#include chat-async/src/bin/client.rs:solution}} ``` diff --git a/src/exercises/concurrency/solutions-morning.md b/src/exercises/concurrency/solutions-morning.md index 40defe9195d3..a31c581eb5e8 100644 --- a/src/exercises/concurrency/solutions-morning.md +++ b/src/exercises/concurrency/solutions-morning.md @@ -5,7 +5,7 @@ ([back to exercise](dining-philosophers.md)) ```rust -{{#include dining-philosophers.rs}} +{{#include dining-philosophers.rs:solution}} ``` ## Link Checker @@ -13,5 +13,5 @@ ([back to exercise](link-checker.md)) ```rust,compile_fail -{{#include link-checker.rs}} +{{#include link-checker.rs:solution}} ``` diff --git a/src/exercises/day-1/for-loops.rs b/src/exercises/day-1/for-loops.rs index 4673ac571ed9..e2d9663d69fb 100644 --- a/src/exercises/day-1/for-loops.rs +++ b/src/exercises/day-1/for-loops.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: transpose fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] { // ANCHOR_END: transpose diff --git a/src/exercises/day-1/luhn.rs b/src/exercises/day-1/luhn.rs index 5fd26ca9790d..63a0c7f9106f 100644 --- a/src/exercises/day-1/luhn.rs +++ b/src/exercises/day-1/luhn.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: luhn pub fn luhn(cc_number: &str) -> bool { // ANCHOR_END: luhn diff --git a/src/exercises/day-1/solutions-afternoon.md b/src/exercises/day-1/solutions-afternoon.md index c8bff12cdfe3..024ba19eb29f 100644 --- a/src/exercises/day-1/solutions-afternoon.md +++ b/src/exercises/day-1/solutions-afternoon.md @@ -5,7 +5,7 @@ ([back to exercise](luhn.md)) ```rust -{{#include luhn.rs}} +{{#include luhn.rs:solution}} ``` ## Pattern matching diff --git a/src/exercises/day-1/solutions-morning.md b/src/exercises/day-1/solutions-morning.md index 6b218a649520..cbc94fb6ccfb 100644 --- a/src/exercises/day-1/solutions-morning.md +++ b/src/exercises/day-1/solutions-morning.md @@ -5,7 +5,7 @@ ([back to exercise](for-loops.md)) ```rust -{{#include for-loops.rs}} +{{#include for-loops.rs:solution}} ``` ### Bonus question diff --git a/src/exercises/day-2/book-library.rs b/src/exercises/day-2/book-library.rs index a084b4caf6f7..14dd6d178875 100644 --- a/src/exercises/day-2/book-library.rs +++ b/src/exercises/day-2/book-library.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: setup struct Library { books: Vec, diff --git a/src/exercises/day-2/solutions-afternoon.md b/src/exercises/day-2/solutions-afternoon.md index 45c10529e680..c4e7965500ac 100644 --- a/src/exercises/day-2/solutions-afternoon.md +++ b/src/exercises/day-2/solutions-afternoon.md @@ -5,5 +5,5 @@ ([back to exercise](strings-iterators.md)) ```rust -{{#include strings-iterators.rs}} +{{#include strings-iterators.rs:solution}} ``` diff --git a/src/exercises/day-2/solutions-morning.md b/src/exercises/day-2/solutions-morning.md index a62cd4a30001..03a2b91c5286 100644 --- a/src/exercises/day-2/solutions-morning.md +++ b/src/exercises/day-2/solutions-morning.md @@ -5,5 +5,5 @@ ([back to exercise](book-library.md)) ```rust -{{#include book-library.rs}} +{{#include book-library.rs:solution}} ``` diff --git a/src/exercises/day-2/strings-iterators.rs b/src/exercises/day-2/strings-iterators.rs index 17e2d4044613..fda344b2d72e 100644 --- a/src/exercises/day-2/strings-iterators.rs +++ b/src/exercises/day-2/strings-iterators.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: prefix_matches pub fn prefix_matches(prefix: &str, request_path: &str) -> bool { // ANCHOR_END: prefix_matches diff --git a/src/exercises/day-3/points-polygons.rs b/src/exercises/day-3/points-polygons.rs index 839d780c0ab5..789408de81f5 100644 --- a/src/exercises/day-3/points-polygons.rs +++ b/src/exercises/day-3/points-polygons.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution #[derive(Debug, Copy, Clone, PartialEq, Eq)] // ANCHOR: Point pub struct Point { diff --git a/src/exercises/day-3/safe-ffi-wrapper.rs b/src/exercises/day-3/safe-ffi-wrapper.rs index bbbfc2c11a7a..ee32719bdbfa 100644 --- a/src/exercises/day-3/safe-ffi-wrapper.rs +++ b/src/exercises/day-3/safe-ffi-wrapper.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: ffi mod ffi { use std::os::raw::{c_char, c_int}; diff --git a/src/exercises/day-3/simple-gui.rs b/src/exercises/day-3/simple-gui.rs index a74cd0ded413..ee4673620f37 100644 --- a/src/exercises/day-3/simple-gui.rs +++ b/src/exercises/day-3/simple-gui.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ANCHOR: solution // ANCHOR: setup pub trait Widget { /// Natural width of `self`. diff --git a/src/exercises/day-3/solutions-afternoon.md b/src/exercises/day-3/solutions-afternoon.md index c4863917a756..7ded2ed5de24 100644 --- a/src/exercises/day-3/solutions-afternoon.md +++ b/src/exercises/day-3/solutions-afternoon.md @@ -5,5 +5,5 @@ ([back to exercise](safe-ffi-wrapper.md)) ```rust -{{#include safe-ffi-wrapper.rs}} +{{#include safe-ffi-wrapper.rs:solution}} ``` diff --git a/src/exercises/day-3/solutions-morning.md b/src/exercises/day-3/solutions-morning.md index df80c3cf330a..a226109eaa31 100644 --- a/src/exercises/day-3/solutions-morning.md +++ b/src/exercises/day-3/solutions-morning.md @@ -5,7 +5,7 @@ ([back to exercise](simple-gui.md)) ```rust -{{#include simple-gui.rs}} +{{#include simple-gui.rs:solution}} ``` ## Points and Polygons @@ -13,5 +13,5 @@ ([back to exercise](points-polygons.md)) ```rust -{{#include points-polygons.rs}} +{{#include points-polygons.rs:solution}} ``` diff --git a/src/exercises/solutions.md b/src/exercises/solutions.md index 333eb92dffac..d4a35351613c 100644 --- a/src/exercises/solutions.md +++ b/src/exercises/solutions.md @@ -5,8 +5,3 @@ You will find solutions to the exercises on the following pages. Feel free to ask questions about the solutions [on GitHub](https://github.com/google/comprehensive-rust/discussions). Let us know if you have a different or better solution than what is presented here. - - -> **Note:** Please ignore the `// ANCHOR: label` and `// ANCHOR_END: label` -> comments you see in the solutions. They are there to make it possible to -> re-use parts of the solutions as the exercises.