`Result` is a better version of the `Option` type that describes possible error instead
"`Result` is a better version of the `Option` type that describes possible `error` instead of possible `absence`".
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
- short_hand: `String`
- long_hand: String
- long_hand: `String`
- desc: String
- desc: `String`
This structure must have associated to it a function called `opt_flag` that initializes the structure.
This structure must have a**function** called `opt_flag` which initializes the structure.
Receiving two references strings and returns the structure `Flag`. It should be used like this:
This **function** receives two strings references and returns a structure `Flag`. Here is an example of its usage:
```rust
```rust
let d = Flag::opt_flag("diff", "gives the difference between two numbers");
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"
// 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>`
A second structure called `FlagsHandler` will be given which just has one element: `flags: HashMap<(String, String), Callback>`
And the following functions associated to it, for you to complete :
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.
- `add_flag`, which 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
- `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.
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.
and functions above. This function will be the callback for the flag associated to it.
You will have to create the following callback functions :
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`.
- `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`, 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`.
- `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
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 being the structure `CipherError`. This structure should be the error type for the function `cipher`
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
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`.
CipherErr with the a true or false if it is validated and the proper atbash cipher.
For this exercise you will have to implement an **error type**.
For this exercise, you will have to implement an **error type**.
The main objective is to create a form validator, where you must implement a
The main objective is to create a form validator, where you must implement an
error type. This must validate the password and the first name. The
error type. This must validate the password and the first name. The
first name must not be empty and the password must have at least 8 char and a combination of alphanumeric and none alphanumeric ASCII characters
first name must not be empty and the password must have **at least 8 char**, a **combination of alphanumeric**, **none-alphanumeric** (ex: <, & or /, ...)
ex: "asDd123=%" => good
ex: "asDd123=%" => good (as 8 char, alphanumeric and non-alphanumeric)\
"asgfD" => error
"asgfD" => error (does only have alphabetic letters)\
"asdsdf2" => error
"asdsdf2" => error (missing none-alphanumeric)\
"sad_#$" => error
"sad\_#$" => error (does not have a combination of alphanumeric)
Create a structure called `Form` that will have the following fields:
Create a structure called `Form` that will have the following fields:
@ -30,8 +30,8 @@ It must have the fields:
- `form_values`, this will be a tuple of strings that will save the value that the user inserted into the form
- `form_values`, this will be a tuple of strings that will save the value that the user inserted into the form
ex: ("password", "asdaSD_")
ex: ("password", "asdaSD\_")
("first_name", "someone")
("first_name", "someone")
- `date`, that will have the date that the error occurred in the format "2020-12-14 09:33:41"
- `date`, that will have the date that the error occurred in the format "2020-12-14 09:33:41"
- `err`, that will have the error description:
- `err`, that will have the error description:
@ -39,6 +39,11 @@ ex: ("password", "asdaSD_")
- "At least 8 characters"
- "At least 8 characters"
- "Combination of different ASCII character types (numbers, letters and none alphanumeric characters)"
- "Combination of different ASCII character types (numbers, letters and none alphanumeric characters)"
Sometimes it is more desirable to catch the failure of some parts of a program instead
Sometimes it is more desirable to catch the failure of some parts of a program instead of just calling panic.
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
You will have to create a structure called `Message`, this structure
must have the following elements:
must have the following elements:
- content: String
- content: String
- user: String
- 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
- `new`, which initializes the structure
- `send_ms`, that only has its implementation type (**self**) as argument and returns an option.
- `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
- 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.
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,
- `check_ms` which:
containing a `bool` and a `string`. This function will execute the function `send_ms` and if the result
- receives as parameters the reference to the structure `Message`
of the option is `None` it should return (false, "ERROR: illegal"). Otherwise it returns `true` and the
- and returns a tuple, containing a `bool` and a `string`:
content of the message sent.
- 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