Ejercicios 89/94/

This commit is contained in:
perro tuerto 2023-03-09 10:44:05 -08:00
parent 39ac0b9f12
commit 5ac6421498
7 changed files with 10 additions and 24 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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!();
}

View File

@ -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!");

View File

@ -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!");

View File

@ -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);
}