`Result` is a better version of the `Option` type that describes possible error instead
of possible absence
"`Result` is a better version of the `Option` type that describes possible `error` instead of possible `absence`".
Create a structure called `Flag`that as the following elements:
Create a structure called `Flag`which has the following elements:
- short_hand: String
- long_hand: String
- desc: String
- short_hand: `String`
- long_hand: `String`
- desc: `String`
This structure must have associated to it a function called `opt_flag` that initializes the structure.
Receiving two references strings and returns the structure `Flag`. It should be used like this:
This structure must have a**function** called `opt_flag` which initializes the structure.
This **function** receives two strings references and returns a structure `Flag`. Here is an example of its usage:
```rust
let d = Flag::opt_flag("diff", "gives the difference between two numbers");
@ -21,26 +20,40 @@ Receiving two references strings and returns the structure `Flag`. It should be
// output: "short hand: -d, long hand: --diff, description: gives the difference between two numbers"
```
It will be given a second structure called `FlagsHandler` that has just one element: `flags: HashMap<(String, String), Callback>`
And the following functions associated to it, for you to complete :
A second structure called `FlagsHandler` will be given which just has one element: `flags: HashMap<(String, String), Callback>`
The following **functions** (methods) associated with `FlagsHandler` are for you to complete :
- `add_flag`, that adds to the HashMap the flag and the Callback function.
- `exec_func`, that executes the function using the flag provided and returns the result, that can
be either a string with the value from the callback or an error.
- `add_flag`, which adds to the HashMap the flag and the Callback function.
- `exec_func`, which executes the function using the flag provided and returns the result, which can be either a string with the value from the callback or an error.
It will also be provided a `type` called `Callback` being a function that is going to be used in the structure
A `type` called `Callback` will also be provided. It is a function which is going to be used in the structure
and functions above. This function will be the callback for the flag associated to it.
You will have to create the following callback functions :
- `div`, that converts the reference strings to `float`s and returns the `Result`, being the division of the `float`s or the standard (std) error: `ParseFloatError`.
- `rem`, that converts the reference strings to `float`s and returns the `Result`, being the remainder of the division of the `float`s or the standard (std) error `ParseFloatError`.
- `div` which converts the reference strings to `float`s and returns the `Result`, being the division of the `float`s or the standard (std) error: `ParseFloatError`.
- `rem` which converts the reference strings to `float`s and returns the `Result`, being the remainder of the division of the `float`s or the standard (std) error `ParseFloatError`.
The Atbash cipher is a encryption method in which each letter of a word is replaced with its mirror letter in the alphabet
The Atbash cipher is an encryption method in which each letter of a word is replaced by its mirror letter in the alphabet.
Your objective is to create a function called `cipher` this must return a Result wrapped in an Option, this result should return either a boolean
or an Error being the structure `CipherError`. This structure should be the error type for the function `cipher`
Your objective is to create a **function** called `cipher` which must return a `Result` wrapped in an `Option`, this result should return either a `boolean`
or an `Error` based on the structure `CipherError`. This structure should be the error type for the **function**`cipher`.
This function should compare the original string wih the ciphered string. returning true if the cipher is correct otherwise the error type
CipherErr with the a true or false if it is validated and the proper atbash cipher.
This function should compare the original `String` with the ciphered `String`. It should return `true` if the cipher is correct. If the cipher is incorrect it should return the error type `CipherErr` with a `boolean` and the expected atbash cipher `String`.
Sometimes it is more desirable to catch the failure of some parts of a program instead
of just calling panic.
Sometimes it is more desirable to catch the failure of some parts of a program instead of just calling panic.
For this exercise you will have to create a message blocker, where you must block the word `stupid`
For this exercise you will have to create a message blocker, where you must block the word `stupid`.
You will have to create a structure called `Message`, this structure
must have the following elements:
@ -14,34 +13,50 @@ must have the following elements:
- user: String
- time_sent: String
The struct must also have a implementation of 2 functions associated to it:
The struct must also have a implementation of 2 **functions** associated with it:
- `new`, that initializes the structure
- `send_ms`, that only has its implementation type (**self**) as argument and returns an option.
This function must return `None` if the content of the message is either **empty** or contains the
word **stupid**. Otherwise it returns the content of the message.
- `new`, which initializes the structure
- `send_ms`, which only has its implementation type (**self**) as argument and returns an option:
- This function must return `None` if the content of the message is either **empty** or contains the word **stupid**. Otherwise it returns the content of the message.
You will have to create two more functions that aren't associated to any structure:
You will have to create two more **functions** that are not associated with any structure:
- `check_ms` that receives as parameters the reference to the structure `Message` and returns a tuple,
containing a `bool` and a `string`. This function will execute the function `send_ms` and if the result
of the option is `None` it should return (false, "ERROR: illegal"). Otherwise it returns `true` and the
content of the message sent.
- `date_format` that creates and formats the date and time that the message was sent, the format should
look like this: **Mon Oct 5 10:22:19 2020**
- `check_ms` which:
- receives as parameters the reference to the structure `Message`
- and returns a tuple, containing a `bool` and a `string`:
- This function will execute the function `send_ms` and if the result of the option is `None`, it should return (false, "ERROR: illegal").Otherwise it returns `true` and the content of the message sent.
- `date_format` which:
- creates and formats the date and time when the message was sent:
- The format should look like this: **Mon Oct 5 10:22:19 2020**