“struct karat” Kode Jawaban

struct karat

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"
}
Cooperative Cassowary

struct in cust

// 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
    }
}
SnefDen

Jawaban yang mirip dengan “struct karat”

Pertanyaan yang mirip dengan “struct karat”

Lebih banyak jawaban terkait untuk “struct karat” di Rust

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya