From 5cb3ef5b8b31e7090b034f8caf53d8e31c8d5962 Mon Sep 17 00:00:00 2001 From: IkaR49 <IkaR49@users.noreply.github.com> Date: Tue, 12 May 2020 23:11:28 +0300 Subject: [PATCH] chore(try_from_into): Add comments with task description (#392) --- exercises/conversions/try_from_into.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index fafa198..757c796 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -13,18 +13,30 @@ struct Color { // I AM NOT DONE +// Your task is to complete this implementation +// and return an Ok result of inner type Color. +// You need create implementation for a tuple of three integer, +// an array of three integer and slice of integer. +// +// Note, that implementation for tuple and array will be checked at compile-time, +// but slice implementation need check slice length! +// Also note, that chunk of correct rgb color must be integer in range 0..=255. + +// Tuple implementation impl TryFrom<(i16, i16, i16)> for Color { type Error = String; fn try_from(tuple: (i16, i16, i16)) -> Result<Self, Self::Error> { } } +// Array implementation impl TryFrom<[i16; 3]> for Color { type Error = String; fn try_from(arr: [i16; 3]) -> Result<Self, Self::Error> { } } +// Slice implementation impl TryFrom<&[i16]> for Color { type Error = String; fn try_from(slice: &[i16]) -> Result<Self, Self::Error> { @@ -44,7 +56,7 @@ fn main() { // With slice we should use `from` function let c3 = Color::try_from(&v[..]); println!("{:?}", c3); - // or take slice within round brackets + // or take slice within round brackets and use Into let c4: Result<Color, _> = (&v[..]).try_into(); println!("{:?}", c4); }