Format code

This commit is contained in:
mo8it 2024-07-12 18:31:23 +02:00
parent 4c8365fe88
commit 59e8f70e55
2 changed files with 18 additions and 16 deletions

View file

@ -4,10 +4,7 @@
// This function should take an array of `Option` elements and returns array of not None elements // This function should take an array of `Option` elements and returns array of not None elements
// TODO fix this function signature // TODO fix this function signature
fn into_dispose_nulls(list: Vec<Option<&str>>) -> Vec<&str> { fn into_dispose_nulls(list: Vec<Option<&str>>) -> Vec<&str> {
list list.into_iter().flatten().collect()
.into_iter()
.flatten()
.collect()
} }
fn main() { fn main() {
@ -37,7 +34,7 @@ mod tests {
#[allow(dead_code)] #[allow(dead_code)]
struct Rectangle { struct Rectangle {
width: i32, width: i32,
height: i32 height: i32,
} }
impl Rectangle { impl Rectangle {
fn new(width: i32, height: i32) -> Self { fn new(width: i32, height: i32) -> Self {
@ -45,10 +42,13 @@ mod tests {
} }
} }
let custom_list = vec![Some(Rectangle::new(1, 2)), None, None, Some(Rectangle::new(3, 4))]; let custom_list = vec![
Some(Rectangle::new(1, 2)),
None,
None,
Some(Rectangle::new(3, 4)),
];
let only_values = into_dispose_nulls(custom_list); let only_values = into_dispose_nulls(custom_list);
assert_eq!(only_values.len(), 2); assert_eq!(only_values.len(), 2);
} }
} }

View file

@ -4,10 +4,7 @@
// Here we added generic type `T` to function signature // Here we added generic type `T` to function signature
// Now this function can be used with vector of any // Now this function can be used with vector of any
fn into_dispose_nulls<T>(list: Vec<Option<T>>) -> Vec<T> { fn into_dispose_nulls<T>(list: Vec<Option<T>>) -> Vec<T> {
list list.into_iter().flatten().collect()
.into_iter()
.flatten()
.collect()
} }
fn main() { fn main() {
@ -36,7 +33,7 @@ mod tests {
fn store_custom_type_on_list() { fn store_custom_type_on_list() {
struct Rectangle { struct Rectangle {
width: i32, width: i32,
height: i32 height: i32,
} }
impl Rectangle { impl Rectangle {
fn new(width: i32, height: i32) -> Self { fn new(width: i32, height: i32) -> Self {
@ -44,7 +41,12 @@ mod tests {
} }
} }
let custom_list = vec![Some(Rectangle::new(1, 2)), None, None, Some(Rectangle::new(3, 4))]; let custom_list = vec![
Some(Rectangle::new(1, 2)),
None,
None,
Some(Rectangle::new(3, 4)),
];
let only_values = into_dispose_nulls(custom_list); let only_values = into_dispose_nulls(custom_list);
assert_eq!(only_values.len(), 2); assert_eq!(only_values.len(), 2);
} }