mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xpetit
46f4ddc49e
|
4 years ago | |
---|---|---|
.. | ||
README.md | 4 years ago |
README.md
roman_numbers_iter
Instructions
Implement the IntoIterator
trait for the RomanNumber
type to enable using a for loop notation. This implementation must allow taking ownership, borrowing and borrowing mutably.
- Taking ownership (this consumes the RomanNumber)
for digit in number {
...
}
- Borrowing immutably (this preserves the RomanNumber)
for digit in &number {
}
- Borrowing mutably (this allow you to modify the RomanNumber without having to return the ownership)
for digit in &mut number {
}
Notions
- https://doc.rust-lang.org/std/iter/trait.IntoIterator.html
- https://doc.rust-lang.org/std/iter/index.html
Expected Functions
use roman_numbers::{RomanDigit, RomanNumber};
impl IntoIterator for &RomanNumber {
}
impl IntoIterator for &mut RomanNumber {
}
impl IntoIterator for RomanNumber {
}
Usage
Here is a program to test your function.
use roman_numbers::RomanNumber;
fn main() {
let number = RomanNumber::from(15);
for digit in &number {
println!("{:?}", digit);
}
println!("{:?}", number);
}
And its output
$ cargo run
RomanNumber([X, X, X, I, I])
RomanNumber([I, X])
RomanNumber([X, L, V])
RomanNumber([Nulla])
$