// AsRef and AsMut allow for cheap reference-to-reference conversions.
// Read more about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html
// and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
// I AM NOT DONE
// Obtain the number of bytes (not characters) in the given argument
// Add the AsRef trait appropriately as a trait bound
fn byte_counter<T>(arg: AsRef<usize>) -> usize {
arg.as_ref().as_bytes().len()
}
but i see the above error . Please any hints how to solve it and I read the chapter of the book but still stuck
fn byte_counter<T: AsRef<str>>(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
fn char_counter<T: AsRef<str>>(arg: T) -> usize {
arg.as_ref().chars().count()
}
Semantically this is the same; the only difference is that with impl Trait you can't specify the type at call site explicitly (through "turbofish" syntax).
Then I think i solved all the challenges with some help,
maybe it's better to leave it for a few days and do the rustlings again before im going to dive into rocket
There's is another option which is using the trait objects, which makes the function be compiled only once and uses arg.as_ref() through a vtable at runtime: