Moved programs to subfolder to avoid overcrowding

in main folder in similar maner to online tutorial
This commit is contained in:
2020-06-10 01:02:33 -04:00
parent f6e5d4aeb3
commit 67b062ab90
6 changed files with 0 additions and 0 deletions

33
1.HelloWorld/testcase.rs Normal file
View File

@@ -0,0 +1,33 @@
//Import the `fmt` module.
use std::fmt;
//Define a structure named `List` containing a `Vec`.
struct List(Vec<i32>);
impl fmt::Display for List{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
//Extract the value using tuple indexing,
//and create a reference to `vec`.
let vec = &self.0;
write!(f, "[")?;
//Iterate over `v` in `vec` while enumerating the iteration count in `count`.
for(count, v) in vec.iter().enumerate(){
//For every element except the first, add a comma.
//Use the ? operator, or try!, to return on errors.
if count != 0{
write!(f, ", ")?;
}
write!(f, "{}: {}", count, v)?;
}
//Close the opened bracket and return a fmt::Result value.
write!(f, "]")
}
}
fn main(){
let v = List(vec![1, 2, 3]);
println!("{}", v);
}