This file contains hidden or 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
use std::hash::Hash; | |
use std::collections::{HashMap, HashSet}; | |
use std::slice; | |
pub type Value = u32; | |
// list of values, assumed to be small to large | |
pub static VALUES: [Value; 5] = [1, 2, 3, 4, 5]; | |
This file contains hidden or 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
use std::hash::Hash; | |
use std::collections::{HashMap, HashSet}; | |
use std::slice; | |
pub type Value = u32; | |
// list of values, assumed to be small to large | |
pub static VALUES: [Value; 5] = [1, 2, 3, 4, 5]; | |
This file contains hidden or 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
use std::thread; | |
use std::sync::Arc; | |
use std::rc::Rc; | |
use std::fmt::Debug ; | |
pub fn get_insertion_index<K: Ord + Debug + Clone>(values: &[K], k: &K) -> usize { | |
let mut index = 0; | |
for v in values{ | |
if *v >= *k { break;} | |
index += 1; |
This file contains hidden or 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
fn main() { | |
do_stuff((42, 0)); | |
do_stuff((0, 42)); | |
do_stuff((0, 0)); | |
do_stuff((123, 456)); | |
} | |
fn do_stuff(point: (u32, u32)) { | |
match point { |
This file contains hidden or 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
pub trait Ast<'a> { | |
fn evaluate(self: Box<Self>) -> Option<Box<Ast<'a> + 'a>>; | |
} | |
pub struct Assignment<'a> { | |
lhs: Option<Box<Ast<'a> + 'a>>, | |
rhs: Option<Box<Ast<'a> + 'a>> | |
} | |
impl<'a> Ast<'a> for Assignment<'a> { |
This file contains hidden or 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
use std::rc::Rc; | |
use std::ops::Deref; | |
//A HasPosition trait and a Body that implements it | |
trait HasPosition { | |
fn get_position(&self) -> i32; | |
} | |
struct Body { | |
position: i32 |
This file contains hidden or 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
use std::rc::Rc; | |
use std::ops::Deref; | |
//A HasPosition trait and a Body that implements it | |
trait HasPosition { | |
fn get_position(&self) -> i32; | |
} | |
struct Body { | |
position: i32 |
This file contains hidden or 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
use std::rc::Rc; | |
use std::ops::Deref; | |
trait HasPosition{ | |
fn get_position(&self) -> i32; | |
} | |
struct Body { | |
position: i32 | |
} |
This file contains hidden or 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
use std::sync::Arc; | |
use std::rc::Rc; | |
use std::fmt::Debug; | |
use std::cell::RefCell; | |
#[derive(Debug, PartialEq, Clone, Copy)] | |
enum NodeType{ | |
Node, | |
Leaf | |
} |
This file contains hidden or 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
fn get_c() -> Box<FnMut(i32)> { | |
Box::new(|val: i32| { | |
println!("value --> {}", val); | |
}) | |
} | |
pub fn set_c<F>(mut callback: F) | |
where F: FnMut(i32) | |
{ | |
callback(100); |