Add rust and serde notes

This commit is contained in:
Wilfried OLLIVIER 2019-07-06 22:42:14 +02:00
parent 9d14bbdf20
commit 87eca7c756
3 changed files with 64 additions and 0 deletions

View file

@ -6,6 +6,8 @@
- [Golang](./dev/golang/main.md) - [Golang](./dev/golang/main.md)
- [Testing](./dev/golang/testing.md) - [Testing](./dev/golang/testing.md)
- [Rust](./dev/rust/main.md)
- [serde](./dev/rust/serde.md)
- [Web](./dev/web/main.md) - [Web](./dev/web/main.md)
- [front](./dev/web/front/main.md) - [front](./dev/web/front/main.md)
- [babel and babel-preset-stage-2](./dev/web/front/babel-preset-stage-2.md) - [babel and babel-preset-stage-2](./dev/web/front/babel-preset-stage-2.md)

1
src/dev/rust/main.md Normal file
View file

@ -0,0 +1 @@
# Rust

61
src/dev/rust/serde.md Normal file
View file

@ -0,0 +1,61 @@
# serde
[Serde](https://serde.rs/) is **rust** create used to _serialize_ and _deserialize_ stuff.
For example, this can be used to deserialize toml into a dedicated struct.
## Example, with toml
Here is how serde after version 1.0 (included) should be used with serialize/deserialize mechanisms.
**Be careful, there is breaaking changes before version 1.0 and you can find confusing docs.**
### `main.rs` file
```rust
// crates
extern crate toml;
extern crate serde;
// uses
use serde::Deserialize;
#[derive(Deserialize)]
struct Config {
name: String,
url: String,
}
fn main() {
let content = r#"name = "example"
url = "https://example.com""#;
let conf: Config = toml::from_str(content).unwrap();
println!("name: {}, url: {}", conf.name, conf.url)
}
```
### `Cargo.toml` file
```toml
[package]
name = "safiste"
version = "0.1.0"
authors = ["El Famoso Safiste"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0.94", features = ["derive"] }
toml = "0.5.1"
```
### Output
```txt
name: example, url: https://example.com
```