Search
 
SCRIPT & CODE EXAMPLE
 

RUST

rust struct default values

struct Point {
    x: i32,
    y: i32
}

impl Default for Point {
    fn default() -> Point {
        Point {
            x: 0,
            y: 1
        }
    }
}

fn main() {
    // initialize a default point
    let p1 = Point { ..Default::default() };

    // initialize a point with default value for all fields except 
    // y that is set to 0
    let p2 = Point { y: 0, ..Default::default() };
    
    println!("{}, {}", p1.x, p1.y); // 0, 1
    println!("{}, {}", p2.x, p2.y); // 0, 0
	
}
Comment

PREVIOUS NEXT
Code Example
Rust :: rust hello world 
Rust :: sleep in rust 
Rust :: rust copy to clipboard 
Rust :: rust lang display 
Rust :: new rust project with cargo 
Rust :: rust iterate vector backwards 
Rust :: armanriazi•rust•pattern•design•interior•mutability•refcell 
Rust :: how to make map in rust language 
Rust :: rust html parser 
Rust :: rust modulus 
Rust :: rust•armanriazi•osstring•vs•path 
Rust :: rust•armanriazi•error•[E0382]: use of moved value: `counter` value moved into closure here, in previous iteration of loop 
Rust :: armanriazi•rust•collection•hashmap•avoid_of_duplicate 
Rust :: rust ceil 
Rust :: rust Clean way to get Option::unwrap_or_else behaviour with an Option<&T 
Rust :: Vector with multiple types in rust 
Rust :: Rust Options Some None using closures 
Rust :: rust array literal 
Lua :: roblox how to make rainbow part 
Lua :: luau region 
Lua :: roblox tween color part 
Lua :: roblox how to find something in table 
Lua :: for i = 1 to n roblox 
Lua :: roblox random number generator 
Lua :: fivem commands lua example 
Lua :: how to make everyone on team see each other name roblox 
Lua :: type lua 
Lua :: Ackermann function lua 
Lua :: lua wiki 
Matlab :: matlab make symbolic matrix 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =