You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
781 B

## borrow
### Instructions
4 years ago
Complete the signature and the body of the `str_len` **function** that receives a string or a string literal and returns its length without taking ownership of the value (i.e, borrowing the value).
4 years ago
### Expected Function (The signature needs to be completed)
```rust
pub fn str_len(s: ) -> usize {
}
```
4 years ago
### Notions
- [Primitive Type str](https://doc.rust-lang.org/std/primitive.str.html)
### Usage
Here is a possible program to test your function :
```rust
use borrow::*;
fn main() {
let s = "hello";
let s1 = "camelCase".to_string();
println!("\tstr_len(\"{}\") = {}", s, str_len(s));
println!("\tstr_len(\"{}\") = {}", s1, str_len(&s1));
}
```
And its output:
```console
$ cargo run
str_len("hello") = 5
str_len("camelCase") = 9
$
```