Horje
rust struct Code Example
rust struct
struct Data {
	randomInfo: String
}

let mut Data {
	randomInfo: "This is a structure"
}

/* 
 The mut keyword defines whether or not you can mutate (change)
 the variable (in this case a structure), so if you don't want tp be able to 
 change the data then don't use the mut keyword. Like so:
*/

let Data {
	randomInfo: "This is a structure"
}
struct in rust
// as example a for a person
struct Person {
    pub name    : String,   // public
    age     : u8,           // private
    // here are all the attributes and there types
}
// impl contains all functions and methods that will be implemented to your struct
impl Person {
    // a function from the class itself
    fn new(name:String, age:u8) -> Self {
      	// crate an instace of the class
        Person {
            name    : name,
            age     : age
        }
    }
    // a method from an object of this class
    fn get_age(self) -> u8 {
        // `self` is the object itself and the same like `this` in java
        self.age
    }
}




Rust

Related
ignore #[warn(dead_code)] Code Example ignore #[warn(dead_code)] Code Example
create file rust Code Example create file rust Code Example
how to split a string by spaces rust Code Example how to split a string by spaces rust Code Example
remove file rust Code Example remove file rust Code Example
rustlang string Code Example rustlang string Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
13