mirror of
https://bitbucket.org/Mattrixwv/rusttutorials.git
synced 2025-12-06 18:43:57 -05:00
Updated to run functions from main function
This commit is contained in:
@@ -48,7 +48,7 @@ impl VeryVerboseEnumOfThingsToDoWithNumbers{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
let pressed = WebEvent::KeyPress('x');
|
let pressed = WebEvent::KeyPress('x');
|
||||||
//`to_owned()` creates an owned `String` from a string slice.
|
//`to_owned()` creates an owned `String` from a string slice.
|
||||||
let pasted = WebEvent::Paste("my text".to_owned());
|
let pasted = WebEvent::Paste("my text".to_owned());
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ enum Color{
|
|||||||
Blue = 0x0000ff,
|
Blue = 0x0000ff,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
//`enums` can be cast as integers.
|
//`enums` can be cast as integers.
|
||||||
println!("zero is {}", Number::Zero as i32);
|
println!("zero is {}", Number::Zero as i32);
|
||||||
println!("one is {}", Number::One as i32);
|
println!("one is {}", Number::One as i32);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ impl List{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
//Create an empty linked list
|
//Create an empty linked list
|
||||||
let mut list = List::new();
|
let mut list = List::new();
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ enum Work{
|
|||||||
Soldier,
|
Soldier,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
// Explicitly `use` each name so they are available without manual scoping.
|
// Explicitly `use` each name so they are available without manual scoping.
|
||||||
//use crate::Status::{Poor, Rich};
|
//use crate::Status::{Poor, Rich};
|
||||||
use Status::{Poor, Rich};
|
use Status::{Poor, Rich};
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ fn square(pnt: Point, side: f32) -> Rectangle{
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
//Create struct with field init shorthand
|
//Create struct with field init shorthand
|
||||||
let name = "Peter";
|
let name = "Peter";
|
||||||
let age = 27;
|
let age = 27;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
//This is a hello world program for rust
|
//This is a hello world program for rust
|
||||||
|
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
//Basic printing
|
//Basic printing
|
||||||
println!("Hello World");
|
println!("Hello World");
|
||||||
let x = 5;
|
let x = 5;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub mod TestcaseList;
|
|||||||
pub mod Formatting;
|
pub mod Formatting;
|
||||||
|
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
// In general, the `{}` will be automatically replaced with any
|
// In general, the `{}` will be automatically replaced with any
|
||||||
// arguments. These will be stringified.
|
// arguments. These will be stringified.
|
||||||
println!("{} days", 31);
|
println!("{} days", 31);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ struct Person<'a>{
|
|||||||
age: u8
|
age: u8
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
//Printing with `{:?}` is similar to with `{}`.
|
//Printing with `{:?}` is similar to with `{}`.
|
||||||
println!("{:?} months in a year.", 12);
|
println!("{:?} months in a year.", 12);
|
||||||
println!("{1:?} {0:?} is the {actor:?} name.",
|
println!("{1:?} {0:?} is the {actor:?} name.",
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl fmt::Display for Complex{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
let minmax = MinMax(0, 14);
|
let minmax = MinMax(0, 14);
|
||||||
|
|
||||||
println!("Compare structures:");
|
println!("Compare structures:");
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ impl Display for Color{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
for city in[
|
for city in[
|
||||||
City{ name: "Dublin", lat: 53.347778, lon: -6.259722 },
|
City{ name: "Dublin", lat: 53.347778, lon: -6.259722 },
|
||||||
City{ name: "Oslo", lat: 59.95, lon: 10.75 },
|
City{ name: "Oslo", lat: 59.95, lon: 10.75 },
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ impl fmt::Display for List{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
let v = List(vec![1, 2, 3]);
|
let v = List(vec![1, 2, 3]);
|
||||||
println!("{}", v);
|
println!("{}", v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ fn analyze_slice(slice: &[i32]){
|
|||||||
println!("the slice has {} elements", slice.len());
|
println!("the slice has {} elements", slice.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
//Fixed-size array (type signature is superfluous)
|
//Fixed-size array (type signature is superfluous)
|
||||||
let xs: [i32; 5] = [1, 2, 3, 4, 5];
|
let xs: [i32; 5] = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
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
|
//Integer addition
|
||||||
println!("1 + 2 = {}", 1u32 + 2);
|
println!("1 + 2 = {}", 1u32 + 2);
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fn transpose(matrix: Matrix) -> Matrix{
|
|||||||
return newMatrix;
|
return newMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
pub fn main(){
|
||||||
//A tuple with a bunch of different types
|
//A tuple with a bunch of different types
|
||||||
let long_tuple = (1u8, 2u16, 3u32, 4u64,
|
let long_tuple = (1u8, 2u16, 3u32, 4u64,
|
||||||
-1i8, -2i16, -3i32, -4i64,
|
-1i8, -2i16, -3i32, -4i64,
|
||||||
|
|||||||
36
src/main.rs
36
src/main.rs
@@ -7,5 +7,39 @@ mod CustomTypes;
|
|||||||
|
|
||||||
|
|
||||||
fn main(){
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user