Last active
January 1, 2025 20:12
-
-
Save hyone/d6018ee1ac8f9496fed839f481eb59d6 to your computer and use it in GitHub Desktop.
Revisions
-
hyone revised this gist
Oct 2, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ struct Slice<'a, T: 'a> { impl <'a, T: ToString> Display for Slice<'a, T> { fn fmt(&self, f: &mut Formatter) -> Result { let xs: Vec<_> = self.data.into_iter().map(|i| i.to_string()).collect(); write!(f, "[{}]", xs.join(", ")) } } @@ -24,9 +24,9 @@ fn main() { let vec: Vec<_> = (1..11).collect(); double_prints(&Slice { data: &array }); //=> Debug: `Slice { data: ["hello", "world", "rust", "programming"] }` // Display: `[hello, world, rust, programming]` double_prints(&Slice { data: &vec }) //=> Debug: `Slice { data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }` // Display: `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]` } -
hyone revised this gist
Oct 1, 2016 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,13 +20,13 @@ fn double_prints<T: Debug + Display>(t: &T) { fn main() { let array = ["hello", "world", "rust", "programming"]; let vec: Vec<_> = (1..11).collect(); double_prints(&Slice { data: &array }); //=> Debug: `Slice { data: [1, 2, 3] }` // Display: `[1,2,3]` double_prints(&Slice { data: &vec }) //=> Debug: `Slice { data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }` // Display: `[1,2,3,4,5,6,7,8,9,10]` } -
hyone revised this gist
Oct 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ struct Slice<'a, T: 'a> { data: &'a [T] } impl <'a, T: ToString> Display for Slice<'a, T> { fn fmt(&self, f: &mut Formatter) -> Result { let xs: Vec<_> = self.data.into_iter().map(|i| i.to_string()).collect(); write!(f, "[{}]", xs.join(",")) -
hyone revised this gist
Oct 1, 2016 . No changes.There are no files selected for viewing
-
hyone revised this gist
Oct 1, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,5 +24,9 @@ fn main() { let array2 = ["hello", "world", "rust", "programming"]; double_prints(&Slice { data: &array1 }); //=> Debug: `Slice { data: [1, 2, 3] }` // Display: `[1,2,3]` double_prints(&Slice { data: &array2 }) //=> Debug: `Slice { data: ["hello", "world", "rust", "programming"] }` // Display: `[hello,world,rust,programming]` } -
hyone renamed this gist
Oct 1, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hyone created this gist
Oct 1, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ use std::fmt::{ Debug, Display, Formatter, Result }; use std::string::ToString; #[derive(Debug)] struct Slice<'a, T: 'a> { data: &'a [T] } impl <'a, T: 'a + ToString> Display for Slice<'a, T> { fn fmt(&self, f: &mut Formatter) -> Result { let xs: Vec<_> = self.data.into_iter().map(|i| i.to_string()).collect(); write!(f, "[{}]", xs.join(",")) } } fn double_prints<T: Debug + Display>(t: &T) { println!("Debug: `{:?}`", t); println!("Display: `{}`", t); } fn main() { let array1 = [1, 2, 3]; let array2 = ["hello", "world", "rust", "programming"]; double_prints(&Slice { data: &array1 }); double_prints(&Slice { data: &array2 }) }