Search
 
SCRIPT & CODE EXAMPLE
 

RUST

set interval Rust

#[allow(dead_code)]
enum Time {
  Millisecond(u8),
  Second(u8),
  Minute(u8),
  Hour(u8)
}

#[allow(dead_code)]
fn set_interval(callback: fn() -> (), time: Time) -> () {
  let duration = match time {
    Time::Millisecond(value) => Duration::from_millis(value as u64),
    Time::Second(value) => Duration::from_secs(value as u64),
    Time::Minute(value) => Duration::from_secs(value as u64 * 60),
    Time::Hour(value) => Duration::from_secs(value as u64 * 60 * 60)
  };

  callback();

  loop {
    sleep(duration);
    callback()
  }
}

fn main() {
  set_interval(|| {
    println!("Hello World after every 1 second")
  }, Time::Second(1))
}
Comment

PREVIOUS NEXT
Code Example
Rust :: armanriazi•rust•error•E0502•cannot borrow `s` as mutable because it is also borrowed as immutable 
Rust :: armanriazi•rust•unsafe•extern•mangling 
Rust :: greater than equal to rust 
Rust :: overwritting print on same line rust 
Rust :: armanriazi•rust•stack•vs•heap 
Rust :: rust•armanriazi•error•cannot be formatted with the default formatter 
Rust :: minimum and maximum numbers for various integer types 
Rust :: armanriazi•rust•concept•mangling 
Rust :: rust•armanriazi•slice•vs•char•vec 
Rust :: armanriazi•rust•refactor•flowcontrol•match•unwrap_or_else 
Rust :: rust•armanriazi•concept•nan 
Lua :: roblox children for loop 
Lua :: roblox get player from character 
Lua :: roblox make region 
Lua :: rgb to hex lua 
Lua :: Pass values to functions from Onclicks roblox 
Lua :: roblox random brick colour 
Lua :: roblox how to get the players mouse 
Lua :: lua infinite 
Lua :: append to array lua 
Lua :: roblox studio rain 
Lua :: lua string to binary 
Lua :: Get Nearest Player fivem 
Lua :: lua code 
Lua :: lua table of alphabet 
Matlab :: how to read dat file in matlab 
Matlab :: Load .mat data in Matlab 
Basic :: hello world in basic 
Elixir :: elixir string to time 
Elixir :: elixir sleep 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =