File: code.md

package info (click to toggle)
rust-presenterm 0.15.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,692 kB
  • sloc: sh: 51; javascript: 36; makefile: 14
file content (108 lines) | stat: -rw-r--r-- 1,756 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
theme:
  override:
    code:
      alignment: left
      background: false
---

Code styling
===

This presentation shows how to:

* Left-align code blocks.
* Have code blocks without background.
* Execute code snippets.

```rust
pub struct Greeter {
    prefix: &'static str,
}

impl Greeter {
    /// Greet someone.
    pub fn greet(&self, name: &str) -> String {
        let prefix = self.prefix;
        format!("{prefix} {name}!")
    }
}

fn main() {
    let greeter = Greeter { prefix: "Oh, hi" };
    let greeting = greeter.greet("Mark");
    println!("{greeting}");
}
```

<!-- end_slide -->

Column layouts
===

The same code as the one before but split into two columns to split the API definition with its usage:

<!-- column_layout: [1, 1] -->

<!-- column: 0 -->

# The `Greeter` type

```rust
pub struct Greeter {
    prefix: &'static str,
}

impl Greeter {
    /// Greet someone.
    pub fn greet(&self, name: &str) -> String {
        let prefix = self.prefix;
        format!("{prefix} {name}!")
    }
}
```

<!-- column: 1 -->

# Using the `Greeter`

```rust
fn main() {
    let greeter = Greeter {
      prefix: "Oh, hi"
    };
    let greeting = greeter.greet("Mark");
    println!("{greeting}");
}
```

<!-- end_slide -->

Snippet execution
===

Run code snippets from the presentation and display their output dynamically.

```python +exec
/// import time
for i in range(0, 5):
    print(f"count is {i}")
    time.sleep(0.5)
```

<!-- end_slide -->

Snippet execution - `stderr`
===

Output from `stderr` will also be shown as output.

```bash +exec
echo "This is a successful command"
sleep 0.5
echo "This message redirects to stderr" >&2
sleep 0.5
echo "This is a successful command again"
sleep 0.5
man # Missing argument
```