features: init, preposition

This commit is contained in:
Horki 2020-09-10 20:58:45 +02:00
parent 3286c5ec19
commit ad18d15cf7
4 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,13 @@
[package]
name = "features"
version = "0.0.1"
edition = "2018"
[lib]
name = "features1"
path = "src/features1.rs"
[features]
english = []
russian = []
korean = []

View file

@ -0,0 +1,5 @@
For this exercise check out the sections:
- [Features](https://doc.rust-lang.org/cargo/reference/features.html)
- [Conditional Compilation](https://doc.rust-lang.org/reference/conditional-compilation.html)
of the Rust Book.

View file

@ -0,0 +1,48 @@
// features1.rs
// Conditional compilation example:
// `cargo +stable test --features "english" --release`
// `cargo +stable test --features "korean" --release`
// `cargo +stable test --features "russian" --release`
// https://doc.rust-lang.org/cargo/reference/features.html
// https://doc.rust-lang.org/reference/conditional-compilation.html
// Also, try `cargo expand` https://github.com/dtolnay/cargo-expand
// `cargo expand --features "russian"`
// Execute `rustlings hint features1` for hints!
// I AM NOT DONE
#[cfg(feature = "korean")]
pub fn hello() -> String {
String::from("안녕하세요!")
}
#[cfg(feature = "russian")]
pub fn hello() -> String {
String::from("Привет мир!")
}
#[cfg(feature = "english")]
pub fn hello() -> String {
String::from("Hello World!")
}
#[cfg(test)]
mod tests {
use crate::hello;
#[test]
fn say_hello() {
#[cfg(feature = "korean")]
let r = "안녕하세요!".to_string();
#[cfg(feature = "english")]
let r = "Hello World!".to_string();
#[cfg(feature = "russian")]
let r = "Привет мир!".to_string();
let a = hello();
assert_eq!(r, a);
}
}

View file

@ -419,6 +419,15 @@ path = "exercises/quiz4.rs"
mode = "test"
hint = "No hints this time ;)"
# FEATURES
[[exercies]]
name = "features1"
path = "exercises/features/src/features1.rs"
mode = "feature"
hint = """TODO: Add some nice hint!"""
features = ["english", "korean", "russian"]
# MOVE SEMANTICS
[[exercises]]