summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-01-23 17:07:06 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-01-23 17:07:06 +0000
commit38029764bb5ff97df1fac69026c52fef239fca90 (patch)
tree71b4286d9b454de7c8b908bcaec5c68d18eb1620
parentb9364b79b0e939bd3e4c4949f0d9b32d19b03858 (diff)
downloadrust-talk-38029764bb5ff97df1fac69026c52fef239fca90.tar.bz2
More stuff
-rw-r--r--presentation.md255
1 files changed, 255 insertions, 0 deletions
diff --git a/presentation.md b/presentation.md
index ea7f4e9..5cdea83 100644
--- a/presentation.md
+++ b/presentation.md
@@ -1643,6 +1643,259 @@ count: false
---
+## Installing Rust
+
+???
+
+- Installation is the final piece of the puzzle.
+- Typically there are two ways that people get hold of software
+
+--
+
+- Distributions
+
+???
+
+- You get it from your software distribution
+- Or...
+
+--
+
+- Download a (source?) tarball/package
+
+???
+
+- You download a tarball/package from the software vendor and build/install it
+
+--
+
+- There _has_ to be something better?
+
+???
+
+- Mmm yes, something better perhaps?
+
+---
+
+class: impact
+
+# `rustup`
+
+???
+
+- The rust community wanted to produce an option which is effective in allowing
+ developers to acquire Rust and associated components such as `clippy` or
+ `rustfmt` as mentioned before.
+- Rustup is the primary official way to get hold of Rust, though by no means the
+ only supported method. Debian, Fedora, etc. package `rustc` `cargo` et al.
+- Rustup allows you to manage multiple versions of the toolchains, supports
+ installing multiple targets to facilitate cross compilation, etc.
+
+---
+
+# Getting Rust
+
+<pre style="font-size: 1.4rem">
+$ curl -sSf https://sh.rustup.rs/ > rustup-init.sh
+$ ... review rustup-init.sh ...
+$ sh rustup-init.sh
+...
+...
+...
+Rust is installed now. Great!
+
+To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
+environment variable. Next time you log in this will be done automatically.
+
+To configure your current shell run source $HOME/.cargo/env
+</pre>
+
+???
+
+- The recommended way to get Rustup if you simply want to get started is just to
+ download it via the `sh.rustup.rs` service. While the website will exhort you
+ to just dump that straight into shell, I do recommend a quick check of the
+ content of the shell script if you want to be absolutely sure.
+
+---
+
+# Hello World?
+
+<pre style="font-size: 1.5rem">
+$ cargo init --bin hello
+<b><span style="color:#0A0"> Created</span></b> binary (application) package
+$
+
+
+
+
+
+
+
+
+
+
+
+
+</pre>
+
+???
+
+First we create the directory and populate it with an initial set of files.
+
+---
+
+count: false
+
+# Hello World?
+
+<pre style="font-size: 1.5rem">
+$ cargo init --bin hello
+<b><span style="color:#0A0"> Created</span></b> binary (application) package
+$ cd hello
+$ cat src/main.rs
+fn main() {
+ println!("Hello, world!");
+}
+$
+
+
+
+
+
+
+
+</pre>
+
+???
+
+How convenient! Cargo automatically creates our binary as hello world, just so
+we can get going
+
+---
+
+count: false
+
+# Hello World?
+
+<pre style="font-size: 1.5rem">
+$ cargo init --bin hello
+<b><span style="color:#0A0"> Created</span></b> binary (application) package
+$ cd hello
+$ cat src/main.rs
+fn main() {
+ println!("Hello, world!");
+}
+$ cargo run
+<b><span style="color:#0A0"> Compiling</span></b> hello v0.1.0 (/tmp/hello)
+<b><span style="color:#0A0"> Finished</span></b> dev [unoptimized + debuginfo] target(s) in 0.29s
+<b><span style="color:#0A0"> Running</span></b> `target/debug/hello`
+Hello, world!
+$
+
+
+</pre>
+
+???
+
+And running the app, cargo will build it and run it, and we see our message.
+
+---
+
+count: false
+
+# Hello World?
+
+<pre style="font-size: 1.5rem">
+$ cargo init --bin hello
+<b><span style="color:#0A0"> Created</span></b> binary (application) package
+$ cd hello
+$ cat src/main.rs
+fn main() {
+ println!("Hello, world!");
+}
+$ cargo run
+<b><span style="color:#0A0"> Compiling</span></b> hello v0.1.0 (/tmp/hello)
+<b><span style="color:#0A0"> Finished</span></b> dev [unoptimized + debuginfo] target(s) in 0.29s
+<b><span style="color:#0A0"> Running</span></b> `target/debug/hello`
+Hello, world!
+$ ls
+Cargo.lock Cargo.toml <b><span style="color:#00A">src</span></b> <b><span style="color:#00A">target</span></b>
+$
+</pre>
+
+???
+
+- Finally we can look at what is in the directory. As you can see, there are
+ a number of files and directories there.
+- `Cargo.toml` describes the metadata for the crate
+- `Cargo.lock` is managed by Cargo and ensures that unless you tell Cargo otherwise
+ it will always use the same versions of your dependencies. This helps with
+ any attempt at reproducibility
+- `src` contains your code
+- `target` is the build directory, it contains the binaries, intermediate content,
+ incremental build caches, etc.
+
+---
+
+# What about a library?
+
+<pre style="font-size: 1.5rem">
+$ cargo init --lib mylib
+<b><span style="color:#0A0"> Created</span></b> library package
+$ cd mylib
+$ cat src/lib.rs
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn it_works() {
+ assert_eq!(2 + 2, 4);
+ }
+}
+$ cargo build
+<b><span style="color:#0A0"> Compiling</span></b> mylib v0.1.0 (/tmp/mylib)
+<b><span style="color:#0A0"> Finished</span></b> dev [unoptimized + debuginfo] target(s) in 0.17s
+$
+</pre>
+
+???
+
+- Libraries come by default with a very basic test to show you how testing works
+- We can build the crate in the normal way
+- But what about running the tests?
+
+---
+
+# What about a library?
+
+<pre style="font-size: 1.5rem">
+$ cargo test
+<b><span style="color:#0A0"> Compiling</span></b> mylib v0.1.0 (/tmp/mylib)
+<b><span style="color:#0A0"> Finished</span></b> dev [unoptimized + debuginfo] target(s) in 0.34s
+<b><span style="color:#0A0"> Running</span></b> target/debug/deps/mylib-b0be8938ca1f0c56
+
+running 1 test
+test tests::it_works ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
+
+<b><span style="color:#0A0"> Doc-tests</span></b> mylib
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
+$
+</pre>
+
+???
+
+- You can see that it ran the tests and the `it_works` test passed as expected
+- Also you can see that it tried to run doc tests but didn't find any. As said
+ before, doc tests are absolutely first class in Rust and hopefully as you
+ develop your library, you'll have plenty of those.
+
+---
+
## The Rust community
- Reddit `/r/rust`
@@ -1668,6 +1921,7 @@ count: false
---
+count: false
class: impact
# Any questions?
@@ -1679,6 +1933,7 @@ something, otherwise questions, or I'm done.
---
+count: false
class: impact
# One final point