This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://gist.github.com/dns2utf8/82641ac26448a722f3022280c0ca455e | |
#[derive(Debug)] | |
struct A { value: isize } | |
impl A { | |
fn borrow_value(&mut self) -> &mut isize { | |
&mut self.value | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://gist.github.com/dns2utf8/379f17cfdd30a90298e1d632a2b86d84 | |
use core::fmt::Debug; | |
#[derive(Debug)] | |
struct A<BeCc: Debug> { | |
data: BeCc, | |
} | |
fn main() { | |
let a = A { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://gist.github.com/dns2utf8/896ab69c2739b530c1318b3bbe4d61ce | |
enum ABC { | |
A, | |
B, | |
C, | |
} | |
// use ABC::*; // <-- enable this | |
fn main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://estada.ch/2020/9/23/my-rust-2021-wishlist-for-the-2021-roadmap/#adl | |
#[derive(Debug)] | |
pub enum SecondaryProcessor { | |
Opening(String), | |
Ready, | |
Writing(String), | |
Reading(String), | |
Closing, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(test)] | |
use std::hint::black_box; | |
#[inline(never)] | |
fn calc1(n: u32) -> u32 { | |
n * n | |
} | |
#[inline(never)] | |
fn calc2(n: u32) -> u32 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://gist.github.com/dns2utf8/799fc958afae896ab40735cfdbb0df21 | |
fn main() { | |
let num = "0x2a"; | |
let parsed = | |
usize::from_str_radix(num.trim_start_matches("0x"), 16).expect("unable to parse num"); | |
println!("Hello, {}!", parsed); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://gist.github.com/dns2utf8/98e3b9977c23c656788be36cca1f9477 | |
use threadpool::Builder; // 1.7.1 | |
fn main() { | |
let max_jobs = 3; | |
let pool = Builder::new().num_threads(1).build(); | |
let maybe_submit = |func| { | |
if pool.queued_count() < max_jobs { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://gist.github.com/dns2utf8/6550ff8ff35205bc718ea8ca4f8b6217 | |
use core::ops::{Deref, DerefMut}; | |
use std::any::Any; | |
#[derive(Default, Clone, Debug)] | |
pub struct Part { | |
pub count: u16, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: https://gist.github.com/dns2utf8/a1288783cdd387f6d3381f8697d98c45 | |
extern crate rand; // 0.6.1 | |
fn main() { | |
let number: f64 = rand::random(); | |
let int = maybe_round(number); | |
println!("Hello, {} => {:?}!", number, int); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Source: https://gist.github.com/dns2utf8/11b541f0b4165f1cc39472c15f494a00 | |
fn main() { | |
let mut result = 0; | |
let list = vec![-8, 30, -42, 32]; | |
println!("init result = {}!", result); | |
println!("init list = {:?}!", list); | |
absolute_max(&mut result, &list); | |
println!("final result = {}!", result); |
NewerOlder