public/subjects/generics/README.md

41 lines
575 B
Markdown
Raw Permalink Normal View History

## generics
### Instructions
2022-06-08 03:46:34 +00:00
Create a **function** named `identity` which calculates the identity of a value (receives any data type and returns the same value).
2021-03-08 04:07:11 +00:00
### Expected Function (signature to be completed)
```rust
2021-03-08 04:07:11 +00:00
pub fn identity(v: _) -> _ {
}
```
### Usage
Here is a program to test your function.
```rust
2021-03-08 04:07:11 +00:00
use generics::*;
fn main() {
println!("{}", identity("Hello, world!"));
println!("{}", identity(3));
}
```
2021-03-08 04:07:11 +00:00
And its output:
```console
$ cargo run
Hello, world!
3
$
```
2022-06-08 03:46:34 +00:00
### Notions
- [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html)