-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Rewrite try_from_into #393
feat: Rewrite try_from_into #393
Conversation
Instead of working with strings, the exercise suggests creating a Color structure from other simple types (tuple, array, slice). closes #392
Hi @ikar49, This looks really good. Thank you for the great work. I have one suggestion here. The hint provided in the
Please feel free to reach out if you have any questions. Thank you so much! Abdou |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ikar49,
Sorry, I completely overlooked something:
I realized the Color
is defined with u8
as inner types while the implementations are asking for i16
. While this may not be a problem by itself, if someone directly converts an i16
to a u8
, there may be some wrapping issues. For instance, the following will compile, but is not really what you would want:
fn main() {
let v = 1000;
println!("{}", v as u8);
}
Evidently, this can be resolved by adding unit tests that makes sure that if a value greater than 255 is provided, then an error is returned.
Please let me know if you have a question about this.
Thank you,
Abdou
Hello @AbdouSeck. Are you suggesting replacing i16 with isize, if I understand correctly? |
Not really. I think it would be fine to just add a test cases to handle when values above 255 are passed. I am thinking of the following tests:
and
and also
These will make sure that the implementations remember to return an error if the values provided are greater than 255. Please let me know if you have any questions. Thank you, Abdou |
I fixed it. What you think about it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ikar49, I think this should take care of all types of out-of-range issues. Thank you so much!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
I've just been going through the rustlings exercises and found this one a little confusing. I could not get the |
English is not my native language, so I may have made some mistakes in the text. I would be grateful if someone could check it out.
closes #392