diff --git a/subjects/own-and-return/README.md b/subjects/own-and-return/README.md index 2eb1672d..0bb0756f 100644 --- a/subjects/own-and-return/README.md +++ b/subjects/own-and-return/README.md @@ -2,9 +2,12 @@ ### Instructions -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 struct `Film` that has one field `name` of type `String`. -Create a function `own_and_return` which takes ownership of the struct, and returns the string. +Create the following two functions: + +- Create a function `take_film_name` it will return the name and consume the film (you should not be able to reuse it after you passed it to the function). +- Create a function `read_film_name` it will return the name without consuming the film (you can call the function multiple times with the same argument). ### Expected functions @@ -13,10 +16,10 @@ pub struct Film { pub name: String, } -pub fn only_return(your_parameter) { +pub fn read_film_name(/* to be implemented */) -> String { } -pub fn own_and_return(your_parameter) { +pub fn take_film_name(/* to be implemented */) -> String { } @@ -29,14 +32,24 @@ Here is a possible program to test your function : ```rust use own_and_return::*; + pub struct Film { pub name: String, } fn main() { - println!("{}", own_and_return(your_argument); - println!("{}", only_return(your_argument); + let my_film = Film { name: "Terminator" }; + println!("{}", take_film_name(/* to be implemented */); + println!("{}", read_film_name(/* to be implemented */); } ``` -And its output should return the name of the film being passed. +And its output: + +```console +$ cargo run +Terminator +Terminator +Terminator +$ +```