diff --git a/exercises/algorithm/algorithm1.rs b/exercises/algorithm/algorithm1.rs index f7a99bf02..132b9f91f 100644 --- a/exercises/algorithm/algorithm1.rs +++ b/exercises/algorithm/algorithm1.rs @@ -2,11 +2,11 @@ single linked list merge This problem requires you to merge two ordered singly linked lists into one ordered singly linked list */ -// I AM NOT DONE + use std::fmt::{self, Display, Formatter}; use std::ptr::NonNull; -use std::vec::*; +use std::{result, vec::*}; #[derive(Debug)] struct Node { @@ -29,13 +29,13 @@ struct LinkedList { end: Option>>, } -impl Default for LinkedList { +impl Default for LinkedList { fn default() -> Self { Self::new() } } -impl LinkedList { +impl LinkedList { pub fn new() -> Self { Self { length: 0, @@ -72,11 +72,53 @@ impl LinkedList { pub fn merge(list_a:LinkedList,list_b:LinkedList) -> Self { //TODO - Self { - length: 0, - start: None, - end: None, + // Self { + // length: 0, + // start: None, + // end: None, + // } + let mut list_c = LinkedList::::new(); + let mut ptr_a = list_a.start; + let mut ptr_b = list_b.start; + while ptr_a.is_some() && ptr_b.is_some() { + let val_a = unsafe { &(*ptr_a.unwrap().as_ptr()).val }; + let val_b = unsafe { &(*ptr_b.unwrap().as_ptr()).val }; + let result = val_a.cmp(val_b); + // if val_a.cmp(val_b) { + // list_c.add(val_a); + // ptr_a = unsafe { ptr_a.unwrap().as_ref().next }; + // } else { + // list_c.add(val_b); + // ptr_b = unsafe { ptr_b.unwrap().as_ref().next }; + // } + match result { + std::cmp::Ordering::Less => { + list_c.add(val_a.clone()); + ptr_a = unsafe { ptr_a.unwrap().as_ref().next }; + } + std::cmp::Ordering::Greater => { + list_c.add(val_b.clone()); + ptr_b = unsafe { ptr_b.unwrap().as_ref().next }; + } + std::cmp::Ordering::Equal => { + list_c.add(val_a.clone()); + list_c.add(val_b.clone()); + ptr_a = unsafe { ptr_a.unwrap().as_ref().next }; + ptr_b = unsafe { ptr_b.unwrap().as_ref().next }; + } + } + } + while ptr_a.is_some() { + let val_a = unsafe { ptr_a.unwrap().as_ref().val.clone() }; + list_c.add(val_a); + ptr_a = unsafe { ptr_a.unwrap().as_ref().next }; + } + while ptr_b.is_some() { + let val_b = unsafe { ptr_b.unwrap().as_ref().val.clone() }; + list_c.add(val_b); + ptr_b = unsafe { ptr_b.unwrap().as_ref().next }; } + list_c } } diff --git a/exercises/algorithm/algorithm10.rs b/exercises/algorithm/algorithm10.rs index a2ad731d0..006fa7b8b 100644 --- a/exercises/algorithm/algorithm10.rs +++ b/exercises/algorithm/algorithm10.rs @@ -2,7 +2,7 @@ graph This problem requires you to implement a basic graph functio */ -// I AM NOT DONE + use std::collections::{HashMap, HashSet}; use std::fmt; @@ -30,6 +30,21 @@ impl Graph for UndirectedGraph { } fn add_edge(&mut self, edge: (&str, &str, i32)) { //TODO + let (from_node, to_node, weight) = edge; + if !self.contains(from_node) { + self.add_node(from_node); + } + if !self.contains(to_node) { + self.add_node(to_node); + } + self.adjacency_table_mutable() + .get_mut(from_node) + .unwrap() + .push((to_node.to_string(), weight)); + self.adjacency_table_mutable() + .get_mut(to_node) + .unwrap() + .push((from_node.to_string(), weight)); } } pub trait Graph { @@ -38,10 +53,23 @@ pub trait Graph { fn adjacency_table(&self) -> &HashMap>; fn add_node(&mut self, node: &str) -> bool { //TODO - true + // true + self.adjacency_table_mutable().insert(node.to_string(), Vec::new()); + true } fn add_edge(&mut self, edge: (&str, &str, i32)) { //TODO + let (from_node, to_node, weight) = edge; + if !self.contains(from_node) { + self.add_node(from_node); + } + if !self.contains(to_node) { + self.add_node(to_node); + } + self.adjacency_table_mutable() + .get_mut(from_node) + .unwrap() + .push((to_node.to_string(), weight)); } fn contains(&self, node: &str) -> bool { self.adjacency_table().get(node).is_some() diff --git a/exercises/algorithm/algorithm2.rs b/exercises/algorithm/algorithm2.rs index 08720ff44..0adafb41d 100644 --- a/exercises/algorithm/algorithm2.rs +++ b/exercises/algorithm/algorithm2.rs @@ -2,7 +2,6 @@ double linked list reverse This problem requires you to reverse a doubly linked list */ -// I AM NOT DONE use std::fmt::{self, Display, Formatter}; use std::ptr::NonNull; @@ -74,6 +73,19 @@ impl LinkedList { } pub fn reverse(&mut self){ // TODO + let mut current = self.start; + let mut temp = None; + while current.is_some() { + let mut current_node = unsafe { current.unwrap().as_mut() }; + temp = current_node.prev; + current_node.prev = current_node.next; + current_node.next = temp; + temp = current; + current = current_node.prev; + } + if temp.is_some() { + self.start = temp; + } } } diff --git a/exercises/algorithm/algorithm3.rs b/exercises/algorithm/algorithm3.rs index 37878d6a7..6da9d5c4c 100644 --- a/exercises/algorithm/algorithm3.rs +++ b/exercises/algorithm/algorithm3.rs @@ -3,10 +3,22 @@ This problem requires you to implement a sorting algorithm you can use bubble sorting, insertion sorting, heap sorting, etc. */ -// I AM NOT DONE -fn sort(array: &mut [T]){ +fn sort(array: &mut [T]){ //TODO + let mut n = array.len(); + let mut swapped = true; + while swapped { + swapped = false; + for i in 1..n { + if array[i - 1] > array[i] { + array.swap(i - 1, i); + swapped = true; + } + } + n -= 1; + } + } #[cfg(test)] mod tests { diff --git a/exercises/algorithm/algorithm4.rs b/exercises/algorithm/algorithm4.rs index 271b772c5..ee2801e2e 100644 --- a/exercises/algorithm/algorithm4.rs +++ b/exercises/algorithm/algorithm4.rs @@ -3,7 +3,7 @@ This problem requires you to implement a basic interface for a binary tree */ -//I AM NOT DONE + use std::cmp::Ordering; use std::fmt::Debug; @@ -51,12 +51,42 @@ where // Insert a value into the BST fn insert(&mut self, value: T) { //TODO + // let new_node = TreeNode::new(value); + match self.root { + Some(ref mut node) => { + if value < node.value { + if node.left.is_none() { + node.left = Some(Box::new(TreeNode::new(value))); + } else { + node.left.as_mut().unwrap().insert(value); + } + } else if value > node.value { + if node.right.is_none() { + node.right = Some(Box::new(TreeNode::new(value))); + } else { + node.right.as_mut().unwrap().insert(value); + } + } + }, + None => { + self.root = Some(Box::new(TreeNode::new(value))); + }, + } } // Search for a value in the BST fn search(&self, value: T) -> bool { //TODO - true + // true + let mut current = &self.root; + while let Some(node) = current { + match value.cmp(&node.value) { + Ordering::Less => current = &node.left, + Ordering::Greater => current = &node.right, + Ordering::Equal => return true, + } + } + false } } @@ -67,6 +97,24 @@ where // Insert a node into the tree fn insert(&mut self, value: T) { //TODO + + match value.cmp(&self.value) { + Ordering::Less => { + if self.left.is_none() { + self.left = Some(Box::new(TreeNode::new(value))); + } else { + self.left.as_mut().unwrap().insert(value); + } + }, + Ordering::Greater => { + if self.right.is_none() { + self.right = Some(Box::new(TreeNode::new(value))); + } else { + self.right.as_mut().unwrap().insert(value); + } + }, + Ordering::Equal => (), + } } } diff --git a/exercises/algorithm/algorithm5.rs b/exercises/algorithm/algorithm5.rs index 8f206d1a9..80cc52bf2 100644 --- a/exercises/algorithm/algorithm5.rs +++ b/exercises/algorithm/algorithm5.rs @@ -3,7 +3,7 @@ This problem requires you to implement a basic BFS algorithm */ -//I AM NOT DONE + use std::collections::VecDeque; // Define a graph @@ -31,6 +31,23 @@ impl Graph { //TODO let mut visit_order = vec![]; + let mut visited = vec![false; self.adj.len()]; + let mut queue = VecDeque::new(); + queue.push_back(start); + visited[start] = true; + + while !queue.is_empty() { + let node = queue.pop_front().unwrap(); + visit_order.push(node); + + for &neighbour in &self.adj[node] { + if !visited[neighbour] { + queue.push_back(neighbour); + visited[neighbour] = true; + } + } + } + visit_order } } diff --git a/exercises/algorithm/algorithm6.rs b/exercises/algorithm/algorithm6.rs index 813146f7c..c21cd216f 100644 --- a/exercises/algorithm/algorithm6.rs +++ b/exercises/algorithm/algorithm6.rs @@ -3,7 +3,7 @@ This problem requires you to implement a basic DFS traversal */ -// I AM NOT DONE + use std::collections::HashSet; struct Graph { @@ -24,6 +24,15 @@ impl Graph { fn dfs_util(&self, v: usize, visited: &mut HashSet, visit_order: &mut Vec) { //TODO + visited.insert(v); + visit_order.push(v); + + for &neighbour in &self.adj[v] { + if !visited.contains(&neighbour) { + self.dfs_util(neighbour, visited, visit_order); + } + } + } // Perform a depth-first search on the graph, return the order of visited nodes diff --git a/exercises/algorithm/algorithm7.rs b/exercises/algorithm/algorithm7.rs index e0c3a5ab2..18c278790 100644 --- a/exercises/algorithm/algorithm7.rs +++ b/exercises/algorithm/algorithm7.rs @@ -3,7 +3,7 @@ This question requires you to use a stack to achieve a bracket match */ -// I AM NOT DONE + #[derive(Debug)] struct Stack { size: usize, @@ -32,7 +32,12 @@ impl Stack { } fn pop(&mut self) -> Option { // TODO - None + // None + if 0 == self.size { + return None; + } + self.size -= 1; + self.data.pop() } fn peek(&self) -> Option<&T> { if 0 == self.size { @@ -102,7 +107,27 @@ impl<'a, T> Iterator for IterMut<'a, T> { fn bracket_match(bracket: &str) -> bool { //TODO - true + // true + let mut stack = Stack::new(); + for c in bracket.chars() { + match c { + '(' => stack.push(')'), + '{' => stack.push('}'), + '[' => stack.push(']'), + ')' | '}' | ']' => { + if let Some(top) = stack.pop() { + if top != c { + return false; + } + } + else { + return false; + } + }, + _ => (), + } + } + stack.is_empty() } #[cfg(test)] diff --git a/exercises/algorithm/algorithm8.rs b/exercises/algorithm/algorithm8.rs index d1d183b84..695a590e4 100644 --- a/exercises/algorithm/algorithm8.rs +++ b/exercises/algorithm/algorithm8.rs @@ -2,7 +2,7 @@ queue This question requires you to use queues to implement the functionality of the stac */ -// I AM NOT DONE + #[derive(Debug)] pub struct Queue { @@ -68,14 +68,25 @@ impl myStack { } pub fn push(&mut self, elem: T) { //TODO + self.q1.enqueue(elem); } pub fn pop(&mut self) -> Result { //TODO - Err("Stack is empty") + // Err("Stack is empty") + if self.q1.is_empty() { + return Err("Stack is empty"); + } + while self.q1.size() > 1 { + self.q2.enqueue(self.q1.dequeue().unwrap()); + } + let result = self.q1.dequeue().unwrap(); + std::mem::swap(&mut self.q1, &mut self.q2); + Ok(result) } pub fn is_empty(&self) -> bool { //TODO - true + // true + self.q1.is_empty() } } diff --git a/exercises/algorithm/algorithm9.rs b/exercises/algorithm/algorithm9.rs index 6c8021a4d..ba2cfa8ab 100644 --- a/exercises/algorithm/algorithm9.rs +++ b/exercises/algorithm/algorithm9.rs @@ -2,7 +2,7 @@ heap This question requires you to implement a binary heap function */ -// I AM NOT DONE + use std::cmp::Ord; use std::default::Default; @@ -38,6 +38,50 @@ where pub fn add(&mut self, value: T) { //TODO + self.count += 1; + self.items.push(value); + self.heapify_up(self.count); + } + + // pub fn remove(&mut self) -> Option { + // //TODO + // if self.is_empty() { + // return None; + // } + // let root = self.items[1]; + // self.items.swap(1, self.count); + // self.items.pop(); + // self.count -= 1; + // self.heapify_down(1); + // Some(root) + // } + + fn heapify_up(&mut self, idx: usize) { + //TODO + let mut idx = idx; + while self.parent_idx(idx) > 0 { + let parent_idx = self.parent_idx(idx); + if (self.comparator)(&self.items[idx], &self.items[parent_idx]) { + self.items.swap(idx, parent_idx); + idx = parent_idx; + } else { + break; + } + } + } + + fn heapify_down(&mut self, idx: usize) { + //TODO + let mut idx = idx; + while self.children_present(idx) { + let smallest_child_idx = self.smallest_child_idx(idx); + if (self.comparator)(&self.items[smallest_child_idx], &self.items[idx]) { + self.items.swap(smallest_child_idx, idx); + idx = smallest_child_idx; + } else { + break; + } + } } fn parent_idx(&self, idx: usize) -> usize { @@ -58,7 +102,16 @@ where fn smallest_child_idx(&self, idx: usize) -> usize { //TODO - 0 + // 0 + let left_child_idx = self.left_child_idx(idx); + let right_child_idx = self.right_child_idx(idx); + if right_child_idx > self.count { + left_child_idx + } else if (self.comparator)(&self.items[left_child_idx], &self.items[right_child_idx]) { + left_child_idx + } else { + right_child_idx + } } } @@ -85,7 +138,18 @@ where fn next(&mut self) -> Option { //TODO - None + // None + if self.is_empty() { + return None; + } + let root = &self.items[1]; + self.items.swap(1, self.count); + // self.items.pop(); + let root = self.items.pop().unwrap(); + self.count -= 1; + self.heapify_down(1); + Some(root) + } } diff --git a/exercises/clippy/clippy3.rs b/exercises/clippy/clippy3.rs index 35021f841..edf70de22 100644 --- a/exercises/clippy/clippy3.rs +++ b/exercises/clippy/clippy3.rs @@ -4,28 +4,28 @@ // // Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint. -// 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); - println!("This Vec is empty, see? {:?}", my_empty_vec); + vec![1, 2, 3, 4, 5].resize(0, 5); + println!("This Vec is empty, see? {:?}", ()); let mut value_a = 45; let mut value_b = 66; // Let's swap these two! - value_a = value_b; - value_b = value_a; + // 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); } diff --git a/exercises/conversions/as_ref_mut.rs b/exercises/conversions/as_ref_mut.rs index 626a36c45..a4bca5bf8 100644 --- a/exercises/conversions/as_ref_mut.rs +++ b/exercises/conversions/as_ref_mut.rs @@ -7,25 +7,27 @@ // Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE + +use std::os::unix::ffi::OsStrExt; // Obtain the number of bytes (not characters) in the given argument. // TODO: Add the AsRef trait appropriately as a trait bound. -fn byte_counter(arg: T) -> usize { +fn byte_counter>(arg: T) -> usize { arg.as_ref().as_bytes().len() } // Obtain the number of characters (not bytes) in the given argument. // TODO: Add the AsRef trait appropriately as a trait bound. -fn char_counter(arg: T) -> usize { +fn char_counter>(arg: T) -> usize { arg.as_ref().chars().count() } // Squares a number using as_mut(). // TODO: Add the appropriate trait bound. -fn num_sq(arg: &mut T) { +fn num_sq>(arg: &mut T) { // TODO: Implement the function body. - ??? + let num = arg.as_mut(); + *num *= *num; } #[cfg(test)] diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs index aba471d92..7d8165b20 100644 --- a/exercises/conversions/from_into.rs +++ b/exercises/conversions/from_into.rs @@ -40,10 +40,30 @@ impl Default for Person { // If while parsing the age, something goes wrong, then return the default of // Person Otherwise, then return an instantiated Person object with the results -// I AM NOT DONE impl From<&str> for Person { fn from(s: &str) -> Person { + if s.len() == 0 { + return Person::default(); + } + let parts: Vec<&str> = s.splitn(2, ',').collect(); + let name = parts[0]; + if name.len() == 0 { + return Person::default(); + } + let age = match parts.get(1) { + Some(age) => { + match age.parse::() { + Ok(age) => age, + Err(_) => return Person::default(), + } + } + None => return Person::default(), + }; + Person { + name: String::from(name), + age, + } } } diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 34472c32c..00770998a 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -31,7 +31,6 @@ enum ParsePersonError { ParseInt(ParseIntError), } -// I AM NOT DONE // Steps: // 1. If the length of the provided string is 0, an error should be returned @@ -52,6 +51,30 @@ enum ParsePersonError { impl FromStr for Person { type Err = ParsePersonError; fn from_str(s: &str) -> Result { + if s.len() == 0 { + return Err(ParsePersonError::Empty); + } + let parts: Vec<&str> = s.split(',').collect(); + if parts.len() != 2 { + return Err(ParsePersonError::BadLen); + } + let name = parts[0]; + if name.len() == 0 { + return Err(ParsePersonError::NoName); + } + let age = match parts.get(1) { + Some(age) => { + match age.parse::() { + Ok(age) => age, + Err(e) => return Err(ParsePersonError::ParseInt(e)), + } + } + None => return Err(ParsePersonError::BadLen), + }; + Ok(Person { + name: name.to_string(), + age, + }) } } diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 32d6ef39e..b12d63ed2 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -27,7 +27,7 @@ enum IntoColorError { IntConversion, } -// I AM NOT DONE + // Your task is to complete this implementation and return an Ok result of inner // type Color. You need to create an implementation for a tuple of three @@ -41,6 +41,14 @@ enum IntoColorError { impl TryFrom<(i16, i16, i16)> for Color { type Error = IntoColorError; fn try_from(tuple: (i16, i16, i16)) -> Result { + if tuple.0 < 0 || tuple.0 > 255 || tuple.1 < 0 || tuple.1 > 255 || tuple.2 < 0 || tuple.2 > 255 { + return Err(IntoColorError::IntConversion); + } + Ok(Color { + red: tuple.0 as u8, + green: tuple.1 as u8, + blue: tuple.2 as u8, + }) } } @@ -48,6 +56,14 @@ impl TryFrom<(i16, i16, i16)> for Color { impl TryFrom<[i16; 3]> for Color { type Error = IntoColorError; fn try_from(arr: [i16; 3]) -> Result { + if arr.iter().any(|&x| x < 0 || x > 255) { + return Err(IntoColorError::IntConversion); + } + Ok(Color { + red: arr[0] as u8, + green: arr[1] as u8, + blue: arr[2] as u8, + }) } } @@ -55,6 +71,17 @@ impl TryFrom<[i16; 3]> for Color { impl TryFrom<&[i16]> for Color { type Error = IntoColorError; fn try_from(slice: &[i16]) -> Result { + if slice.len() != 3 { + return Err(IntoColorError::BadLen); + } + if slice.iter().any(|&x| x < 0 || x > 255) { + return Err(IntoColorError::IntConversion); + } + Ok(Color { + red: slice[0] as u8, + green: slice[1] as u8, + blue: slice[2] as u8, + }) } } diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index 414cef3a0..54c907300 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -10,11 +10,10 @@ // Execute `rustlings hint using_as` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn average(values: &[f64]) -> f64 { let total = values.iter().sum::(); - total / values.len() + total / values.len() as f64 } fn main() { diff --git a/exercises/tests/Cargo.lock b/exercises/tests/Cargo.lock new file mode 100644 index 000000000..d3a8d8c09 --- /dev/null +++ b/exercises/tests/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "tests8" +version = "0.0.1" diff --git a/exercises/tests/Cargo.toml b/exercises/tests/Cargo.toml new file mode 100644 index 000000000..646d1f04e --- /dev/null +++ b/exercises/tests/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "tests8" +version = "0.0.1" +edition = "2021" +[[bin]] +name = "tests8" +path = "tests8.rs" \ No newline at end of file diff --git a/exercises/tests/build.rs b/exercises/tests/build.rs index aa518cef2..0ad68ee1f 100644 --- a/exercises/tests/build.rs +++ b/exercises/tests/build.rs @@ -10,15 +10,17 @@ fn main() { .duration_since(std::time::UNIX_EPOCH) .unwrap() .as_secs(); // What's the use of this timestamp here? - let your_command = format!( - "Your command here with {}, please checkout exercises/tests/build.rs", - timestamp - ); + // let your_command = format!( + // "Your command here with {}, please checkout exercises/tests/build.rs", + // timestamp + // ); + let your_command = format!("rustc-env=TEST_FOO={}", timestamp); println!("cargo:{}", your_command); // In tests8, we should enable "pass" feature to make the // testcase return early. Fill in the command to tell // Cargo about that. - let your_command = "Your command here, please checkout exercises/tests/build.rs"; + // let your_command = "Your command here, please checkout exercises/tests/build.rs"; + let your_command = "rustc-cfg=feature=\"pass\""; println!("cargo:{}", your_command); } diff --git a/exercises/tests/tests5.rs b/exercises/tests/tests5.rs index 0cd5cb256..4314f4ab9 100644 --- a/exercises/tests/tests5.rs +++ b/exercises/tests/tests5.rs @@ -22,7 +22,6 @@ // Execute `rustlings hint tests5` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE /// # Safety /// @@ -32,7 +31,9 @@ unsafe fn modify_by_address(address: usize) { // code's behavior and the contract of this function. You may use the // comment of the test below as your format reference. unsafe { - todo!("Your code goes here") + // todo!("Your code goes here") + let value = address as *mut u32; + *value = 0xAABBCCDD; } } diff --git a/exercises/tests/tests6.rs b/exercises/tests/tests6.rs index 4c913779d..1aed80dcb 100644 --- a/exercises/tests/tests6.rs +++ b/exercises/tests/tests6.rs @@ -7,7 +7,6 @@ // Execute `rustlings hint tests6` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE struct Foo { a: u128, @@ -20,8 +19,10 @@ struct Foo { unsafe fn raw_pointer_to_box(ptr: *mut Foo) -> Box { // SAFETY: The `ptr` contains an owned box of `Foo` by contract. We // simply reconstruct the box from that pointer. - let mut ret: Box = unsafe { ??? }; - todo!("The rest of the code goes here") + let mut ret: Box = unsafe { Box::from_raw(ptr) }; + // todo!("The rest of the code goes here") + ret.b = Some("hello".to_owned()); + ret } #[cfg(test)] diff --git a/exercises/tests/tests7.rs b/exercises/tests/tests7.rs index 66b37b72d..09574783e 100644 --- a/exercises/tests/tests7.rs +++ b/exercises/tests/tests7.rs @@ -34,7 +34,6 @@ // Execute `rustlings hint tests7` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn main() {} diff --git a/exercises/tests/tests8.rs b/exercises/tests/tests8.rs index ce7e35d8d..b9eb0fb10 100644 --- a/exercises/tests/tests8.rs +++ b/exercises/tests/tests8.rs @@ -7,7 +7,6 @@ // Execute `rustlings hint tests8` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE fn main() {} diff --git a/exercises/tests/tests9.rs b/exercises/tests/tests9.rs index ea2a8ec02..0c3b39bc2 100644 --- a/exercises/tests/tests9.rs +++ b/exercises/tests/tests9.rs @@ -27,7 +27,6 @@ // // You should NOT modify any existing code except for adding two lines of attributes. -// I AM NOT DONE extern "Rust" { fn my_demo_function(a: u32) -> u32; @@ -36,9 +35,15 @@ extern "Rust" { mod Foo { // No `extern` equals `extern "Rust"`. + #[no_mangle] fn my_demo_function(a: u32) -> u32 { a } + + #[no_mangle] + fn my_demo_function_alias(a: u32) -> u32 { + a + } } #[cfg(test)]