mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-01-14 00:00:02 +03:00
Compare commits
No commits in common. "a55e84835995b87cdcdb7f746ac9d0fb477a5586" and "4e4b65711a20ae3d02baa79d8295da2b30ec7dd2" have entirely different histories.
a55e848359
...
4e4b65711a
|
@ -2,11 +2,10 @@
|
|||
// 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.
|
||||
|
||||
// Obtain the number of bytes (not characters) in the given argument
|
||||
// (`.len()` returns the number of bytes in a string).
|
||||
// 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().len()
|
||||
arg.as_ref().as_bytes().len()
|
||||
}
|
||||
|
||||
// Obtain the number of characters (not bytes) in the given argument.
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
// 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.
|
||||
|
||||
// Obtain the number of bytes (not characters) in the given argument
|
||||
// (`.len()` returns the number of bytes in a string).
|
||||
// Obtain the number of bytes (not characters) in the given argument.
|
||||
fn byte_counter<T: AsRef<str>>(arg: T) -> usize {
|
||||
arg.as_ref().len()
|
||||
arg.as_ref().as_bytes().len()
|
||||
}
|
||||
|
||||
// Obtain the number of characters (not bytes) in the given argument.
|
||||
|
|
Loading…
Reference in a new issue