examples/code.md
This presentation shows how to:
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}");
}
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 -->Greeter typepub struct Greeter {
prefix: &'static str,
}
impl Greeter {
/// Greet someone.
pub fn greet(&self, name: &str) -> String {
let prefix = self.prefix;
format!("{prefix} {name}!")
}
}
Greeterfn main() {
let greeter = Greeter {
prefix: "Oh, hi"
};
let greeting = greeter.greet("Mark");
println!("{greeting}");
}
Run code snippets from the presentation and display their output dynamically.
/// import time
for i in range(0, 5):
print(f"count is {i}")
time.sleep(0.5)
stderrOutput from stderr will also be shown as output.
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