2020-12-18 18:27:11 +01:00
|
|
|
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
|
|
|
|
#+OPTIONS: author:t broken-links:nil c:nil creator:nil
|
|
|
|
#+OPTIONS: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t
|
|
|
|
#+OPTIONS: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t
|
|
|
|
#+OPTIONS: timestamp:t title:t toc:t todo:t |:t
|
2020-12-21 14:09:32 +01:00
|
|
|
#+TITLE: Rust, Rocket and Diesel
|
|
|
|
#+SUBTITLE: Web apps with rust
|
|
|
|
#+DESCRIPTION: An introduction to Rust, Rocket and Diesel.
|
2020-12-18 18:27:11 +01:00
|
|
|
#+KEYWORDS: rust rocket diesel
|
2020-12-21 11:04:02 +01:00
|
|
|
#+AUTHOR: \href{mailto:rocket-presentation@onders.org}{finga}
|
2020-12-18 18:27:11 +01:00
|
|
|
#+EMAIL: rocket-presentation@onders.org
|
|
|
|
#+LANGUAGE: en
|
|
|
|
#+SELECT_TAGS: export
|
|
|
|
#+EXCLUDE_TAGS: noexport
|
|
|
|
#+CREATOR: Emacs 26.1 (Org mode 9.1.9)
|
|
|
|
|
|
|
|
#+OPTIONS: H:2
|
|
|
|
#+LATEX_CLASS: beamer
|
|
|
|
#+LATEX_CLASS_OPTIONS: [aspectration=1610]
|
2020-12-21 11:04:02 +01:00
|
|
|
# #+LATEX_HEADER: \hypersetup{colorlinks=true,linkcolor=gray}
|
|
|
|
#+LATEX_HEADER: \hypersetup{colorlinks=true,linkcolor=black,urlcolor=gray}
|
2020-12-18 18:27:11 +01:00
|
|
|
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_act(Act) %4BEAMER_col(Col) %8BEAMER_opt(Opt)
|
|
|
|
#+BEAMER_THEME: Frankfurt
|
|
|
|
#+BEAMER_COLOR_THEME: seagull
|
|
|
|
#+BEAMER_FONT_THEME:
|
|
|
|
#+BEAMER_INNER_THEME:
|
|
|
|
#+BEAMER_OUTER_THEME:
|
|
|
|
#+BEAMER_HEADER: \institute[INST]{\href{https://cccsbg.at}{cccsbg}}
|
|
|
|
|
|
|
|
* Rust
|
|
|
|
|
|
|
|
** What is Rust?
|
2020-12-21 11:04:02 +01:00
|
|
|
#+BEGIN_CENTER
|
|
|
|
#+LaTeX:\includegraphics[width = 0.65\textwidth]{img/Bruine_roest_op_tarwe_(Puccinia_recondita_f.sp._tritici_on_Triticum_aestivum).jpg}
|
|
|
|
#+END_CENTER
|
|
|
|
|
2020-12-21 14:09:32 +01:00
|
|
|
*** Rust, the language
|
2020-12-21 11:04:02 +01:00
|
|
|
- About 10 years old (2010)
|
|
|
|
- Memory safe without gcing, optional ref counting
|
|
|
|
- Ownership, lifetimes, traits
|
|
|
|
- Variables are immutable by default and can be shadowed
|
|
|
|
- Performance of idiomatic Rust is comparable to the performance
|
|
|
|
of idiomatic cpp
|
|
|
|
|
2020-12-21 15:11:43 +01:00
|
|
|
** Where to get further information?
|
2020-12-21 11:04:02 +01:00
|
|
|
|
2020-12-21 14:09:32 +01:00
|
|
|
*** Docs...
|
2020-12-21 11:04:02 +01:00
|
|
|
- [[https://doc.rust-lang.org/book/][The rust book]] (~$ rustup docs --book~), [[https://doc.rust-lang.org/rust-by-example/][Rust by example]]
|
|
|
|
- [[https://doc.rust-lang.org/std/][The Rust Standard Library]]
|
|
|
|
- [[https://cheats.rs][cheats.rs]]
|
|
|
|
- [[https://cargo.io][cargo.io]]/[[https://lib.rs][lib.rs]]
|
|
|
|
|
2020-12-21 14:09:32 +01:00
|
|
|
*** Chat (Discord)
|
|
|
|
- [[https://discord.gg/rust-lang][The Rust Programming Language]]
|
|
|
|
- [[https://discord.com/invite/tcbkpyQ][The Rust Programming Language Community Server]]
|
|
|
|
|
2020-12-21 11:04:02 +01:00
|
|
|
** What are we going to use?
|
|
|
|
|
|
|
|
*** Definitely
|
2020-12-21 15:11:43 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
- [[https://rocket.rs][rocket]]
|
|
|
|
- [[https://diesel.rs][diesel]]
|
|
|
|
- log
|
2020-12-21 11:04:02 +01:00
|
|
|
|
|
|
|
*** Maybe
|
2020-12-21 15:11:43 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
- anyhow
|
|
|
|
- lettre
|
|
|
|
- sha3
|
|
|
|
- serde
|
|
|
|
- chrono
|
2020-12-21 11:04:02 +01:00
|
|
|
|
|
|
|
** How to install
|
|
|
|
|
|
|
|
*** Install Rust
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
$ curl --proto '=https' --tlsv1.2 -sSf \
|
|
|
|
https://sh.rustup.rs | sh
|
|
|
|
#+END_SRC
|
|
|
|
|
2020-12-21 14:09:32 +01:00
|
|
|
*** Install nightly Rust (needed for Rocket)
|
2020-12-21 11:04:02 +01:00
|
|
|
#+BEGIN_SRC sh
|
|
|
|
$ rustup toolchain install nightly
|
|
|
|
#+END_SRC
|
|
|
|
|
2020-12-21 14:09:32 +01:00
|
|
|
*** Install rustfmt (code formatter)
|
2020-12-21 11:04:02 +01:00
|
|
|
#+BEGIN_SRC sh
|
|
|
|
$ rustup component add rustfmt
|
|
|
|
#+END_SRC
|
|
|
|
|
2020-12-21 14:09:32 +01:00
|
|
|
*** Install clippy (linter and static code analysis)
|
2020-12-21 11:04:02 +01:00
|
|
|
#+BEGIN_SRC sh
|
|
|
|
$ rustup component add clippy
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
* Rocket
|
|
|
|
|
|
|
|
** What is Rocket?
|
2020-12-21 14:09:32 +01:00
|
|
|
#+BEGIN_QUOTE
|
|
|
|
Rocket is a web framework for Rust that makes it simple to write
|
|
|
|
fast, secure web applications without sacrificing flexibility,
|
|
|
|
usability, or type safety.
|
|
|
|
#+END_QUOTE
|
|
|
|
|
|
|
|
*** Features
|
|
|
|
|
|
|
|
**** Col left
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:END:
|
|
|
|
- Type Safe
|
|
|
|
- Extensible
|
|
|
|
- Templating
|
|
|
|
- Cookies
|
|
|
|
|
|
|
|
**** Col right
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:END:
|
|
|
|
- Streams
|
|
|
|
- Testing (Unit tests)
|
|
|
|
- Typed URIs
|
|
|
|
|
2020-12-21 15:11:43 +01:00
|
|
|
** Where to get further information?
|
2020-12-21 14:09:32 +01:00
|
|
|
|
|
|
|
*** Docs...
|
2020-12-21 15:11:43 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
- [[https://rocket.rs][rocket.rs]]
|
2020-12-21 14:09:32 +01:00
|
|
|
- [[https://rocket.rs/v0.4/guide/][Rocket Guide]]
|
|
|
|
- [[https://api.rocket.rs/v0.4/rocket/][Rocket API docs]]
|
|
|
|
- [[https://github.com/SergioBenitez/Rocket/tree/v0.4/examples][Examples]]
|
|
|
|
|
|
|
|
*** Chat
|
2020-12-21 15:11:43 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
2020-12-21 14:09:32 +01:00
|
|
|
- Matrix: [[https://chat.mozilla.org/#/room/%23rocket:mozilla.org][#rocket:mozilla.org]]
|
|
|
|
- IRC on Freenode: [[https://kiwiirc.com/client/chat.freenode.net/#rocket][#rocket]]
|
2020-12-21 11:04:02 +01:00
|
|
|
|
|
|
|
* Diesel
|
|
|
|
|
|
|
|
** What is an ORM?
|
2020-12-21 15:11:43 +01:00
|
|
|
Object-relational-mapping is a programming technique for converting
|
|
|
|
data between incompatible type systems using the paradigms of your
|
|
|
|
programming language.
|
|
|
|
|
|
|
|
*** Pros
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
- Models are DRY (don't repeat yourself)
|
|
|
|
- Cleaner separation
|
|
|
|
- Prepared and sanitised queries
|
|
|
|
- Changes are versioned
|
|
|
|
|
|
|
|
*** Cons
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
- Debugging can get more complicated (performance)
|
|
|
|
- No need to learn SQL
|
|
|
|
|
|
|
|
** Prerequisites ~diesel_cli~
|
|
|
|
|
|
|
|
*** Setup Diesel for default DBMS
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
$ sudo apt install libpq-dev libsqlite3-dev \
|
|
|
|
default-libmysqlclient-dev
|
|
|
|
$ cargo install diesel_cli
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** Setup Diesel for SQLite only
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
$ sudo apt install libsqlite3-dev
|
|
|
|
$ cargo install diesel_cli -no-default-features \
|
|
|
|
--features sqlite
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** How does that look in Rust
|
|
|
|
|
|
|
|
*** Define a struct
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.50
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
#+BEGIN_SRC rust
|
|
|
|
#[derive(Queryable)]
|
|
|
|
pub struct NewComment<'a> {
|
|
|
|
name: &'a str,
|
|
|
|
email: &'a str,
|
|
|
|
comment: &'a str,
|
|
|
|
}
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
*** Insert something
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
#+BEGIN_SRC rust
|
|
|
|
let user = NewUser {
|
|
|
|
name: "foo",
|
|
|
|
email: "foo@bar.baz",
|
|
|
|
comment: "A comment",
|
|
|
|
};
|
|
|
|
|
|
|
|
insert_into(comments)
|
|
|
|
.values(&user)
|
|
|
|
.execute(conn);
|
|
|
|
#+END_SRC
|
2020-12-21 11:04:02 +01:00
|
|
|
|
2020-12-21 15:11:43 +01:00
|
|
|
** Where to get further information?
|
|
|
|
|
|
|
|
*** Docs...
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
- [[https://diesel.rs][diesel.rs]]
|
|
|
|
- [[https://diesel.rs/guides/][Diesel Guides]]
|
|
|
|
- [[https://docs.diesel.rs/master/diesel/index.html][Diesel API docs]]
|
|
|
|
- [[https://github.com/diesel-rs/diesel/tree/master/examples][Examples]] (minimalistic)
|
|
|
|
|
|
|
|
*** Support
|
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
|
|
|
- [[https://gitter.im/diesel-rs/diesel][Gitter]]
|
|
|
|
- [[https://discourse.diesel.rs/][Discourse Forum]]
|
2020-12-21 11:04:02 +01:00
|
|
|
|
|
|
|
* Lets code something
|
|
|
|
|
2020-12-21 15:11:43 +01:00
|
|
|
** Lets create a small web app
|
|
|
|
|
2020-12-21 11:04:02 +01:00
|
|
|
* Conclusion
|
|
|
|
|
|
|
|
** What did we do?
|
|
|
|
|
|
|
|
** What did you hopefully learn!
|
|
|
|
|
2020-12-21 14:09:32 +01:00
|
|
|
** Two small projects
|
|
|
|
|
|
|
|
*** [[https://git.onders.org/finga/ldap0r][ldap0r]]
|
2020-12-21 15:11:43 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
2020-12-21 14:09:32 +01:00
|
|
|
- LDAP password reset tool
|
|
|
|
- ($\sim$ 300 SloC)
|
|
|
|
- First release
|
|
|
|
- Tests
|
|
|
|
|
|
|
|
*** [[https://git.onders.org/finga/filerly][filerly]]
|
2020-12-21 15:11:43 +01:00
|
|
|
:PROPERTIES:
|
|
|
|
:BEAMER_col: 0.45
|
|
|
|
:BEAMER_env: block
|
|
|
|
:END:
|
2020-12-21 14:09:32 +01:00
|
|
|
- File sharing a la NextCloud
|
|
|
|
- Not ready yet, work in progress...
|
2020-12-21 11:04:02 +01:00
|
|
|
|
|
|
|
** The End
|
|
|
|
#+BEGIN_CENTER
|
|
|
|
#+LaTeX:\includegraphics[width = 0.3\textwidth]{img/goodbye.jpg}
|
|
|
|
|
|
|
|
\Huge
|
|
|
|
Thanks for your attention!!1!
|
|
|
|
|
|
|
|
This is the end..
|
|
|
|
#+END_CENTER
|