59 lines
1.5 KiB
Markdown
59 lines
1.5 KiB
Markdown
|
up:: [[Rust]]
|
||
|
tags::
|
||
|
|
||
|
## This is rust fundamental syntactical concepts
|
||
|
These concepts are for reference only, showcasing the different uses of the syntax
|
||
|
|
||
|
[Comprehensive Rust](https://google.github.io/comprehensive-rust/welcome-day-1.html)
|
||
|
|
||
|
|
||
|
```rust
|
||
|
// This class is designed to teach the fundamentals of Rust to a new programmer.
|
||
|
// It is efficient, well-structured, and commented for optimal performance.
|
||
|
|
||
|
// Define a struct to hold the data for our class
|
||
|
struct RustBasics {
|
||
|
// Data fields
|
||
|
variable_1: i32,
|
||
|
variable_2: String,
|
||
|
variable_3: f64,
|
||
|
}
|
||
|
|
||
|
// Implement the class
|
||
|
impl RustBasics {
|
||
|
// Constructor to initialize a new instance of RustBasics
|
||
|
fn new(var_1: i32, var_2: String, var_3: f64) -> RustBasics {
|
||
|
RustBasics {
|
||
|
variable_1: var_1,
|
||
|
variable_2: var_2,
|
||
|
variable_3: var_3,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Method to access the value of variable_1
|
||
|
fn get_variable_1(&self) -> i32 {
|
||
|
self.variable_1
|
||
|
}
|
||
|
|
||
|
// Method to access the value of variable_2
|
||
|
fn get_variable_2(&self) -> &str {
|
||
|
&self.variable_2
|
||
|
}
|
||
|
|
||
|
// Method to access the value of variable_3
|
||
|
fn get_variable_3(&self) -> f64 {
|
||
|
self.variable_3
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
// Create a new instance of RustBasics
|
||
|
let basics = RustBasics::new(1, String::from("hello"), 3.14);
|
||
|
|
||
|
// Print out the values of the variables
|
||
|
println!("variable_1: {}", basics.get_variable_1());
|
||
|
println!("variable_2: {}", basics.get_variable_2());
|
||
|
println!("variable_3: {}", basics.get_variable_3());
|
||
|
}
|
||
|
```
|