Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

class in rust

// Rust does not have class
// Rust have `struct` and `impl`, they have the same class performance

struct Person {
	name: String,
    age: usize
}

impl Person {
	// This associated function have the same `constrator` performance
	fn new(name: String, age: usize) -> Self {
    return Self {name, age};
    }
    fn get_name(&self) -> String {
    	return self.name;
    }
    fn change_name(&mut self, new_name: String) -> () {
    	self.name = new_name;
    }
}
 
PREVIOUS NEXT
Tagged: #class #rust
ADD COMMENT
Topic
Name
9+3 =