Skip to content

Instantly share code, notes, and snippets.

View flukejones's full-sized avatar

Luke Jones flukejones

View GitHub Profile
@flukejones
flukejones / callbacks.rs
Created December 3, 2016 06:02 — forked from aisamanra/callbacks.rs
Creating a HashMap of closures in Rust
#![feature(unboxed_closures)]
#![feature(core)]
#![feature(io)]
use std::old_io::stdio::{stdin};
use std::collections::HashMap;
// This is our toy state example.
#[derive(Debug)]
struct State {
@flukejones
flukejones / playground.rs
Created December 4, 2016 20:57 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(core_intrinsics)]
pub trait Deserialize: Sized {
fn deserialize(String) -> Self;
}
struct Position(i32, i32);
struct Velocity(i32, i32);
impl Deserialize for Position {
@flukejones
flukejones / inheritance.rs
Last active February 21, 2019 21:40 — forked from MCluck90/inheritance.rs
Inheritance-like problem in Rust
/// Problem: there is a lot of duplication in function implementations.
/// The two types should have the same interface but use a different underlying type.
///
/// How can I reduce the amount of duplication and avoid having to update the code in two places?
/// In other languages, I would define a base class which accepts a generic type for the `SoundSource`s
/// but I don't know how to solve this sort of problem in Rust.
struct Sound {
// Shared properties
is_playing: bool,
@flukejones
flukejones / Profile Rust on Linux.md
Created July 29, 2023 00:31 — forked from KodrAus/Profile Rust on Linux.md
Profiling Rust Applications

Profiling performance

Using perf:

$ perf record -g binary
$ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg

NOTE: See @GabrielMajeri's comments below about the -g option.