Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim off licenses when showing solutions #1212

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/exercises/bare-metal/compass/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/exercises/bare-metal/rtc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/exercises/bare-metal/rtc/src/pl031.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
4 changes: 2 additions & 2 deletions src/exercises/bare-metal/solutions-afternoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
```
2 changes: 1 addition & 1 deletion src/exercises/bare-metal/solutions-morning.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
([back to exercise](compass.md))

```rust,compile_fail
{{#include compass/src/main.rs}}
{{#include compass/src/main.rs:solution}}
```
1 change: 1 addition & 0 deletions src/exercises/concurrency/chat-async/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/exercises/concurrency/chat-async/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/exercises/concurrency/dining-philosophers-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/exercises/concurrency/dining-philosophers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/exercises/concurrency/link-checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/exercises/concurrency/solutions-afternoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}}
```

4 changes: 2 additions & 2 deletions src/exercises/concurrency/solutions-morning.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
([back to exercise](dining-philosophers.md))

```rust
{{#include dining-philosophers.rs}}
{{#include dining-philosophers.rs:solution}}
```

## Link Checker

([back to exercise](link-checker.md))

```rust,compile_fail
{{#include link-checker.rs}}
{{#include link-checker.rs:solution}}
```
1 change: 1 addition & 0 deletions src/exercises/day-1/for-loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/exercises/day-1/luhn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/exercises/day-1/solutions-afternoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
([back to exercise](luhn.md))

```rust
{{#include luhn.rs}}
{{#include luhn.rs:solution}}
```

## Pattern matching
Expand Down
2 changes: 1 addition & 1 deletion src/exercises/day-1/solutions-morning.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
([back to exercise](for-loops.md))

```rust
{{#include for-loops.rs}}
{{#include for-loops.rs:solution}}
```
### Bonus question

Expand Down
1 change: 1 addition & 0 deletions src/exercises/day-2/book-library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Book>,
Expand Down
2 changes: 1 addition & 1 deletion src/exercises/day-2/solutions-afternoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
([back to exercise](strings-iterators.md))

```rust
{{#include strings-iterators.rs}}
{{#include strings-iterators.rs:solution}}
```
2 changes: 1 addition & 1 deletion src/exercises/day-2/solutions-morning.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
([back to exercise](book-library.md))

```rust
{{#include book-library.rs}}
{{#include book-library.rs:solution}}
```
1 change: 1 addition & 0 deletions src/exercises/day-2/strings-iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/exercises/day-3/points-polygons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/exercises/day-3/safe-ffi-wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 1 addition & 0 deletions src/exercises/day-3/simple-gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion src/exercises/day-3/solutions-afternoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
([back to exercise](safe-ffi-wrapper.md))

```rust
{{#include safe-ffi-wrapper.rs}}
{{#include safe-ffi-wrapper.rs:solution}}
```
4 changes: 2 additions & 2 deletions src/exercises/day-3/solutions-morning.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
([back to exercise](simple-gui.md))

```rust
{{#include simple-gui.rs}}
{{#include simple-gui.rs:solution}}
```

## Points and Polygons

([back to exercise](points-polygons.md))

```rust
{{#include points-polygons.rs}}
{{#include points-polygons.rs:solution}}
```
5 changes: 0 additions & 5 deletions src/exercises/solutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.