mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
Compare commits
2 commits
4e4b65711a
...
a55e848359
Author | SHA1 | Date | |
---|---|---|---|
a55e848359 | |||
2653c3c4d4 |
|
@ -2,10 +2,11 @@
|
||||||
// about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html and
|
// 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.
|
// https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
|
||||||
|
|
||||||
// Obtain the number of bytes (not characters) in the given argument.
|
// Obtain the number of bytes (not characters) in the given argument
|
||||||
|
// (`.len()` returns the number of bytes in a string).
|
||||||
// TODO: Add the `AsRef` trait appropriately as a trait bound.
|
// TODO: Add the `AsRef` trait appropriately as a trait bound.
|
||||||
fn byte_counter<T>(arg: T) -> usize {
|
fn byte_counter<T>(arg: T) -> usize {
|
||||||
arg.as_ref().as_bytes().len()
|
arg.as_ref().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain the number of characters (not bytes) in the given argument.
|
// Obtain the number of characters (not bytes) in the given argument.
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
// about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html and
|
// 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.
|
// https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
|
||||||
|
|
||||||
// Obtain the number of bytes (not characters) in the given argument.
|
// Obtain the number of bytes (not characters) in the given argument
|
||||||
|
// (`.len()` returns the number of bytes in a string).
|
||||||
fn byte_counter<T: AsRef<str>>(arg: T) -> usize {
|
fn byte_counter<T: AsRef<str>>(arg: T) -> usize {
|
||||||
arg.as_ref().as_bytes().len()
|
arg.as_ref().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain the number of characters (not bytes) in the given argument.
|
// Obtain the number of characters (not bytes) in the given argument.
|
||||||
|
|
Loading…
Reference in a new issue