Skip to content

Commit

Permalink
Fix test workflow by ignoring incomplete Rust code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Mar 18, 2024
1 parent 2c648ce commit 9d62ab8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
28 changes: 14 additions & 14 deletions src/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ and most idiomatic way to express this logic in Rust is by defining a method nam
For our counter interface, we only need to properly increment or decrement the `value` of our `Counter` struct based on the `Message`
we just defined:

```rust
```rust,ignore
impl Counter {
fn update(&mut self, message: Message) {
match message {
Expand All @@ -85,28 +85,28 @@ impl Counter {

Great! Now we are ready to process user interactions. For instance, imagine we initialized our counter like this:

```rust
```rust,ignore
let mut counter = Counter { value: 0 };
```

And let's say we wanted to simulate a user playing with our interface for a bit—pressing the increment button twice
and then the decrement button once. We could easily compute the final state of our counter with our __update logic__:

```rust
```rust,ignore
counter.update(Message::Increment);
counter.update(Message::Increment);
counter.update(Message::Decrement);
```

This would cause our `Counter` to end up with a `value` of `1`:

```rust
```rust,ignore
assert_eq!(counter.value, 1);
```

In fact, we have just written a simple test for our application logic:

```rust
```rust,ignore
#[test]
fn it_counts_properly() {
let mut counter = Counter { value: 0 };
Expand Down Expand Up @@ -154,7 +154,7 @@ These values are normally created using a _helper function_ from the `widget` mo

For our buttons, we can use the `button` helper:

```rust
```rust,ignore
use iced::widget::button;
let increment = button("+");
Expand All @@ -174,7 +174,7 @@ for our counter value?
While iced does not really have a `number` widget, it does have a more generic `text` widget that can be used
to display any kind of text—numbers included:

```rust
```rust,ignore
use iced::widget::text;
let counter = text(15);
Expand All @@ -191,7 +191,7 @@ __six__ different ways to order them! However, the order we want is: `increment`

A very simple way of describing this order is to create a list with our widgets:

```rust
```rust,ignore
let interface = vec![increment, counter, decrement];
```

Expand All @@ -205,7 +205,7 @@ manage the position of existing widgets. And since widgets are just values, they

The kind of vertical layout that we need for our counter can be achieved with the `column` widget:

```rust
```rust,ignore
use iced::widget::column;
let interface = column![increment, counter, decrement];
Expand All @@ -226,7 +226,7 @@ In iced, every widget has a specific type that enables further configuration usi
helper returns an instance of [the `Button` type], which has an `on_press` method we can use to define the message it must
__produce__ when a user presses the button:

```rust
```rust,ignore
use iced::widget::button;
let increment = button("+").on_press(Message::Increment);
Expand Down Expand Up @@ -257,7 +257,7 @@ We are almost there! There is only one thing left to do: connecting our applicat

Let's bring together all the view logic we have written so far:

```rust
```rust,ignore
use iced::widget::{button, column, text};
// The buttons
Expand All @@ -280,7 +280,7 @@ our update logic is triggered, the text widget will display the new `value`.

We can easily do this by running our view logic in a method of our `Counter`—just like we did with our update logic:

```rust
```rust,ignore
use iced::widget::{button, column, text};
impl Counter {
Expand Down Expand Up @@ -310,7 +310,7 @@ Instead of throwing the `interface` away, we need to return it. Remember, the pu
to dictate the widgets of our user interface; and the content of the `interface` variable is precisely the
description of the interface we want:

```rust
```rust,ignore
use iced::widget::{button, column, text, Column};
impl Counter {
Expand Down Expand Up @@ -347,7 +347,7 @@ let's just inline everything:
<img alt="A classical counter interface" src="resources/counter-interface.svg" width="50%">
</div>

```rust
```rust,ignore
use iced::widget::{button, column, text, Column};
impl Counter {
Expand Down
16 changes: 8 additions & 8 deletions src/the-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Let's try to get a better understanding of the lifetime of an interface by explo
In fact, we have actually started writing a runtime already! When [we implemented the update logic of our counter](first-steps.md#update-logic),
we wrote a very small test that simulated a user:
```rust
```rust,ignore
#[test]
fn it_counts_properly() {
let mut counter = Counter { value: 0 };
Expand All @@ -58,7 +58,7 @@ involved—far from what we actually want. Still, it's a great start! Let's try
### Initializing the State
Our small runtime is already initializing the application state properly:

```rust
```rust,ignore
// Initialize the state
let mut counter = Counter { value: 0 };
```
Expand All @@ -74,7 +74,7 @@ struct Counter {

And then, we simply use `Counter::default` in our runtime:

```rust
```rust,ignore
// Initialize the state
let mut counter = Counter::default();
```
Expand All @@ -93,7 +93,7 @@ and then render the widgets returned by our __view logic__—properly laid out,
What? You have no clue of how to do that? Don't worry, I have this magical function: `display`. It takes a reference to
any interface and displays it to the user. It totally works!

```rust
```rust,ignore
use magic::display;
# // Initialize the state
Expand All @@ -116,7 +116,7 @@ the interactions and produce all the relevant __messages__ that our widgets spec
How? With some more magic, of course! I just found this `interact` function inside of my top hat—it takes an
interface and produces the __messages__ that correspond to the latest interactions of the user.

```rust
```rust,ignore
use magic::{display, interact};
# // Initialize the state
Expand All @@ -141,7 +141,7 @@ react properly to the user, we need to update our __state__ accordingly for each

Luckily, there are no more magic tricks involved in this step—we can just use our __update logic__:

```rust
```rust,ignore
# use magic::{display, interact};
#
# // Initialize the state
Expand Down Expand Up @@ -171,7 +171,7 @@ And then... Do it all over once again!

This is a loop! And no, loops aren't very magical—not when we write Rust, at least:

```rust
```rust,ignore
use magic::{display, interact};
// Initialize the state
Expand Down Expand Up @@ -214,7 +214,7 @@ its own magic[^magic]—so you don't need to worry about learning the dark arts

If we want to run our `Counter`, all we have to do is call [`run`]:

```rust
```rust,ignore
# use iced::widget::{button, column, text, Column};
#
pub fn main() -> iced::Result {
Expand Down

0 comments on commit 9d62ab8

Please sign in to comment.