Ejercicios 89/94/
This commit is contained in:
parent
39ac0b9f12
commit
5ac6421498
|
@ -6,12 +6,10 @@
|
|||
// check clippy's suggestions from the output to solve the exercise.
|
||||
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::f32;
|
||||
|
||||
fn main() {
|
||||
let pi = 3.14f32;
|
||||
let pi = std::f32::consts::PI;
|
||||
let radius = 5.00f32;
|
||||
|
||||
let area = pi * f32::powi(radius, 2);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
// clippy2.rs
|
||||
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let mut res = 42;
|
||||
let option = Some(12);
|
||||
for x in option {
|
||||
if let Some(x) = option {
|
||||
res += x;
|
||||
}
|
||||
println!("{}", res);
|
||||
|
|
|
@ -1,28 +1,24 @@
|
|||
// clippy3.rs
|
||||
// Here's a couple more easy Clippy fixes, so you can see its utility.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[allow(unused_variables, unused_assignments)]
|
||||
fn main() {
|
||||
let my_option: Option<()> = None;
|
||||
if my_option.is_none() {
|
||||
my_option.unwrap();
|
||||
}
|
||||
my_option.unwrap();
|
||||
|
||||
let my_arr = &[
|
||||
-1, -2, -3
|
||||
-1, -2, -3,
|
||||
-4, -5, -6
|
||||
];
|
||||
println!("My array! Here it is: {:?}", my_arr);
|
||||
|
||||
let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5);
|
||||
let my_empty_vec: std::vec::Vec<i32> = vec![];
|
||||
println!("This Vec is empty, see? {:?}", my_empty_vec);
|
||||
|
||||
let mut value_a = 45;
|
||||
let mut value_b = 66;
|
||||
// Let's swap these two!
|
||||
value_a = value_b;
|
||||
value_b = value_a;
|
||||
std::mem::swap(&mut value_a, &mut value_b);
|
||||
println!("value a: {}; value b: {}", value_a, value_b);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// macros1.rs
|
||||
// Execute `rustlings hint macros1` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
|
@ -10,5 +8,5 @@ macro_rules! my_macro {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
my_macro();
|
||||
my_macro!();
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
// macros2.rs
|
||||
// Execute `rustlings hint macros2` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
my_macro!();
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
// Make me compile, without taking the macro out of the module!
|
||||
// Execute `rustlings hint macros3` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
mod macros {
|
||||
#[macro_export]
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
// macros4.rs
|
||||
// Execute `rustlings hint macros4` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
macro_rules! my_macro {
|
||||
() => {
|
||||
println!("Check out my macro!");
|
||||
}
|
||||
};
|
||||
($val:expr) => {
|
||||
println!("Look at this other macro: {}", $val);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue