Search
 
SCRIPT & CODE EXAMPLE
 

RUST

rust global variables

static SOME_INT: i32 = 5;
static SOME_STR: &'static str = "A static string";
static SOME_STRUCT: MyStruct = MyStruct {
    number: 10,
    string: "Some string",
};
static mut db: Option<sqlite::Connection> = None;

fn main() {
    println!("{}", SOME_INT);
    println!("{}", SOME_STR);
    println!("{}", SOME_STRUCT.number);
    println!("{}", SOME_STRUCT.string);

    unsafe {
        db = Some(open_database());
    }
}

struct MyStruct {
    number: i32,
    string: &'static str,
}

/* Note:
	The initial access to the static mut has to be unsafe.
*/
Comment

PREVIOUS NEXT
Code Example
Rust :: rust colorful terminal 
Rust :: new rust project with cargo 
Rust :: rust lang start a new project 
Rust :: rust lang function is never used: rustc(dead_code) 
Rust :: find smallest number in vec rust 
Rust :: concat string rust 
Rust :: rust argv 
Rust :: where in Rust 
Rust :: armanriazi•rust•borrowchecker•lifetime•static 
Rust :: sort reverse rust 
Rust :: rust•armanriazi•method 
Rust :: armanriazi•rust•collection•hashmap•avoid_of_duplicate 
Rust :: armanriazi•rust•error•E0220•associated type `` not found for `Self` 
Rust :: Counting bits Kernighan style 
Rust :: armanriazi•rust•mem•doublefree 
Rust :: armanriazi•rust•thread•rayon•join•workstealing 
Rust :: primitive data types in rust 
Lua :: roblox for children loop 
Lua :: absolute value in lua 
Lua :: roblox __index and __newindex 
Lua :: lua drawinrect 
Lua :: lua click button 
Lua :: return lua 
Lua :: string.match roblox 
Lua :: hello world in lua 
Lua :: draw circle love2d 
Lua :: lua pairs 
Lua :: lua table concanation 
Matlab :: matlab for loop matrix 
Matlab :: matlab variables 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =