diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 1b3d840..f9e2a5e 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -6,6 +6,8 @@ - [Golang](./dev/golang/main.md) - [Testing](./dev/golang/testing.md) + - [Rust](./dev/rust/main.md) + - [serde](./dev/rust/serde.md) - [Web](./dev/web/main.md) - [front](./dev/web/front/main.md) - [babel and babel-preset-stage-2](./dev/web/front/babel-preset-stage-2.md) diff --git a/src/dev/rust/main.md b/src/dev/rust/main.md new file mode 100644 index 0000000..2f1d5ef --- /dev/null +++ b/src/dev/rust/main.md @@ -0,0 +1 @@ +# Rust diff --git a/src/dev/rust/serde.md b/src/dev/rust/serde.md new file mode 100644 index 0000000..ce895db --- /dev/null +++ b/src/dev/rust/serde.md @@ -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 +``` \ No newline at end of file