Updated to run functions from main function

This commit is contained in:
2020-06-11 14:16:57 -04:00
parent 3dc9661907
commit 3457bd6ed8
15 changed files with 49 additions and 15 deletions

View File

@@ -48,7 +48,7 @@ impl VeryVerboseEnumOfThingsToDoWithNumbers{
}
}
fn main(){
pub fn main(){
let pressed = WebEvent::KeyPress('x');
//`to_owned()` creates an owned `String` from a string slice.
let pasted = WebEvent::Paste("my text".to_owned());

View File

@@ -15,7 +15,7 @@ enum Color{
Blue = 0x0000ff,
}
fn main(){
pub fn main(){
//`enums` can be cast as integers.
println!("zero is {}", Number::Zero as i32);
println!("one is {}", Number::One as i32);

View File

@@ -47,7 +47,7 @@ impl List{
}
}
fn main(){
pub fn main(){
//Create an empty linked list
let mut list = List::new();

View File

@@ -11,7 +11,7 @@ enum Work{
Soldier,
}
fn main(){
pub fn main(){
// Explicitly `use` each name so they are available without manual scoping.
//use crate::Status::{Poor, Rich};
use Status::{Poor, Rich};

View File

@@ -41,7 +41,7 @@ fn square(pnt: Point, side: f32) -> Rectangle{
return rect;
}
fn main(){
pub fn main(){
//Create struct with field init shorthand
let name = "Peter";
let age = 27;

View File

@@ -5,7 +5,7 @@
//This is a hello world program for rust
fn main(){
pub fn main(){
//Basic printing
println!("Hello World");
let x = 5;

View File

@@ -11,7 +11,7 @@ pub mod TestcaseList;
pub mod Formatting;
fn main(){
pub fn main(){
// In general, the `{}` will be automatically replaced with any
// arguments. These will be stringified.
println!("{} days", 31);

View File

@@ -14,7 +14,7 @@ struct Person<'a>{
age: u8
}
fn main(){
pub fn main(){
//Printing with `{:?}` is similar to with `{}`.
println!("{:?} months in a year.", 12);
println!("{1:?} {0:?} is the {actor:?} name.",

View File

@@ -39,7 +39,7 @@ impl fmt::Display for Complex{
}
}
fn main(){
pub fn main(){
let minmax = MinMax(0, 14);
println!("Compare structures:");

View File

@@ -31,7 +31,7 @@ impl Display for Color{
}
}
fn main(){
pub fn main(){
for city in[
City{ name: "Dublin", lat: 53.347778, lon: -6.259722 },
City{ name: "Oslo", lat: 59.95, lon: 10.75 },

View File

@@ -27,7 +27,7 @@ impl fmt::Display for List{
}
}
fn main(){
pub fn main(){
let v = List(vec![1, 2, 3]);
println!("{}", v);
}

View File

@@ -6,7 +6,7 @@ fn analyze_slice(slice: &[i32]){
println!("the slice has {} elements", slice.len());
}
fn main(){
pub fn main(){
//Fixed-size array (type signature is superfluous)
let xs: [i32; 5] = [1, 2, 3, 4, 5];

View File

@@ -3,7 +3,7 @@ Integers 1, floats 1.2, characters 'a', strings "abc", booleans true and the uni
Integers can, alternatively, be expressed using hexadecimal, octal or binary notation using these prefixes respectively: 0x, 0o or 0b.
*/
fn main(){
pub fn main(){
//Integer addition
println!("1 + 2 = {}", 1u32 + 2);

View File

@@ -23,7 +23,7 @@ fn transpose(matrix: Matrix) -> Matrix{
return newMatrix;
}
fn main(){
pub fn main(){
//A tuple with a bunch of different types
let long_tuple = (1u8, 2u16, 3u32, 4u64,
-1i8, -2i16, -3i32, -4i64,

View File

@@ -7,5 +7,39 @@ mod CustomTypes;
fn main(){
println!("Hello World");
//1 Hello World
//1.1 Comments
//HelloWorld::Comments::main();
//1.2 Formatted print
//HelloWorld::FormattedPrint::main();
//1.2.1
//HelloWorld::FormattedPrint::Debugging::main();
//1.2.2
//HelloWorld::FormattedPrint::Display::main();
//1.2.2.1
//HelloWorld::FormattedPrint::TestcaseList::main();
//1.2.3
//HelloWorld::FormattedPrint::Formatting::main();
//2 Primitives
//2.1 LiteralsAndOperators
//Primitives::LiteralsAndOperators::main();
//2.2 Tuples
//Primitives::Tuples::main();
//2.3 ArraysAndSlices
//Primitives::ArraysAndSlices::main();
//3 Custom Types
//3.1 Structures
//CustomTypes::Structures::main();
//3.2 Enums
//CustomTypes::Enums::main();
//3.2.1 Use
//CustomTypes::Enums::Use::main();
//3.2.2 C-Like
//CustomTypes::Enums::CLike::main();
//3.2.3 Testcase - Linked-list
//CustomTypes::Enums::TestCaseLinkedList::main();
//3.3 Constants
//CustomTypes::Constants::main();
}