Browse Source

docs(print-and-consume): add description of exercise

DEV-4017-prototypes-exercise-1-animals
eslopfer 2 years ago
parent
commit
0fc87521e6
  1. 34
      subjects/print-and-consume/README.md

34
subjects/print-and-consume/README.md

@ -1,20 +1,25 @@
## print_and_consume
## own_and_return
### Instructions
Create a function `print_and_consume` which takes a `String`, print the string with a new line at the end and consume it (the string can't be used after the function is called).
Create a function `only_return` that takes a `struct` Film that has one Field of type `String` and returns the string without owning it.
Create a function `only_print` that takes a `String` and print it with a new line without consuming it.
Create a function `own_and_return` which takes ownership of the struct, and returns the string.
### Expected functions
```rust
pub fn print_and_consume(argument) {
pub struct Film {
pub name: String,
}
pub fn only_print(argument) {
pub fn only_return(your_parameter) {
}
pub fn own_and_return(your_parameter) {
}
```
### Usage
@ -22,15 +27,16 @@ pub fn only_print(argument) {
Here is a possible program to test your function :
```rust
use print_and_consume::*;
fn main() {}
```
use own_and_return::*;
And its output:
```console
$ cargo run
pub struct Film {
pub name: String,
}
$
fn main() {
println!("{}", own_and_return(your_argument);
println!("{}", only_return(your_argument);
}
```
And its output should return the name of the film being passed.

Loading…
Cancel
Save