Merge pull request #1279 from tkburis/main

Minor changes
This commit is contained in:
liv 2022-12-23 16:44:02 +01:00 committed by GitHub
commit 4ede64b729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 13 deletions

View File

@ -5,21 +5,22 @@
// I AM NOT DONE
// Obtain the number of bytes (not characters) in the given argument
// Add the AsRef trait appropriately as a trait bound
// Obtain the number of bytes (not characters) in the given argument.
// TODO: Add the AsRef trait appropriately as a trait bound.
fn byte_counter<T>(arg: T) -> usize {
arg.as_ref().as_bytes().len()
}
// Obtain the number of characters (not bytes) in the given argument
// Add the AsRef trait appropriately as a trait bound
// Obtain the number of characters (not bytes) in the given argument.
// TODO: Add the AsRef trait appropriately as a trait bound.
fn char_counter<T>(arg: T) -> usize {
arg.as_ref().chars().count()
}
// Squares a number using as_mut(). Add the trait bound as is appropriate and
// implement the function body.
// Squares a number using as_mut().
// TODO: Add the appropriate trait bound.
fn num_sq<T>(arg: &mut T) {
// TODO: Implement the function body.
???
}

View File

@ -6,10 +6,10 @@
// This function returns how much icecream there is left in the fridge.
// If it's before 10PM, there's 5 pieces left. At 10PM, someone eats them
// all, so there'll be no more left :(
// TODO: Return an Option!
fn maybe_icecream(time_of_day: u16) -> Option<u16> {
// We use the 24-hour system here, so 10PM is a value of 22 and 12AM is a value of 0
// The Option output should gracefully handle cases where time_of_day > 23.
// TODO: Complete the function body - remember to return an Option!
???
}

View File

@ -42,7 +42,7 @@ mod my_module {
#[cfg(test)]
mod tests {
// TODO: What do we have to import to have `transformer` in scope?
// TODO: What do we need to import to have `transformer` in scope?
use ???;
use super::Command;

View File

@ -2,7 +2,7 @@
// Time to implement some traits!
//
// Your task is to implement the trait
// `AppendBar' for the type `String'.
// `AppendBar` for the type `String`.
//
// The trait AppendBar has only one function,
// which appends "Bar" to any object
@ -16,7 +16,7 @@ trait AppendBar {
}
impl AppendBar for String {
//Add your code here
// TODO: Implement `AppendBar` for type `String`.
}
fn main() {

View File

@ -1,7 +1,7 @@
// traits2.rs
//
// Your task is to implement the trait
// `AppendBar' for a vector of strings.
// `AppendBar` for a vector of strings.
//
// To implement this trait, consider for
// a moment what it means to 'append "Bar"'
@ -17,7 +17,7 @@ trait AppendBar {
fn append_bar(self) -> Self;
}
//TODO: Add your code here
// TODO: Implement trait `AppendBar` for a vector of strings.
#[cfg(test)]
mod tests {

View File

@ -695,7 +695,7 @@ name = "traits2"
path = "exercises/traits/traits2.rs"
mode = "test"
hint = """
Notice how the trait takes ownership of 'self',and returns `Self'.
Notice how the trait takes ownership of 'self',and returns `Self`.
Try mutating the incoming string vector. Have a look at the tests to see
what the result should look like!