Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bstrie's full-sized avatar

bstrie bstrie

View GitHub Profile
@luser
luser / source-count
Created June 15, 2018 19:36
count of source file lines by extension for source files compiled into a macOS Firefox Nightly build
.cpp 3111001
.h 1272859
.c 1207323
.cc 303090
.rs 246356
.mm 57859
.hh 15850
.cxx 14731
.api 1854
.hxx 802
@spacejam
spacejam / rr-with-rust.md
Last active March 13, 2024 18:51
using rr with rust

using rust with rr

rr is a great debugging tool. it records a trace of a program's execution, as well as the results of any syscalls it executes, so that you can "rewind" while you debug, and get deterministic forward and reverse instrumented playback. it works with rust, but by default if you try it out, it could be pretty ugly when you inspect variables. if this bothers you, configure gdb to use a rust pretty-printer

rr is probably in your system's package manager.

usage

Rust RFC 2005 "Match Ergonomics" was just accepted. However there was a copy-paste error in the summary that led to some confusion about what it was actually doing. Here's a quick run down of the details that matter to users:

TL;DR version:

Before this change, matching on references works like this:

let by_ref: &MyEnum;
let by_mut: &mut MyEnum;
anonymous
anonymous / playground.rs
Created March 23, 2016 10:10
Shared via Rust Playground
#![feature(unboxed_closures, fn_traits)]
fn get_fn_ptr<A, C: Fn<A>>(_: &C) -> extern "rust-call" fn(&(), A) -> C::Output {
let fn_ptr: extern "rust-call" fn(&(), A) -> C::Output = unsafe {
std::mem::transmute(<C as std::ops::Fn<A>>::call as usize)
};
fn_ptr
}
fn main() {
anonymous
anonymous / playground.rs
Created March 23, 2016 09:56
Shared via Rust Playground
#![feature(unboxed_closures, fn_traits)]
fn get_fn_ptr<C: Fn() -> ()>(_: &C) -> extern "rust-call" fn(&(), ()) -> () {
let fn_ptr: extern "rust-call" fn(&(), ()) -> () = unsafe { std::mem::transmute(<C as std::ops::Fn<()>>::call as usize) };
fn_ptr
}
fn main() {
let closure = ||{ println!("hi") };
let ptr = get_fn_ptr(&closure);
anonymous
anonymous / playground.rs
Created March 23, 2016 08:25
Shared via Rust Playground
#![feature(unboxed_closures, fn_traits)]
fn get_fn_ptr<C: Fn() -> ()>(_: &C) -> extern "rust-call" fn(&C, ()) -> () {
<C as std::ops::Fn<()>>::call
}
fn main() {
println!("{:x}", get_fn_ptr(&||{}) as usize);
}
@Gankra
Gankra / gist:155234908dae0d984fe5
Created March 19, 2015 20:56
mutable singly-linked list
struct List<T> {
head: Option<Box<Node<T>>>
}
struct Node<T> {
elem: T,
next: Option<Box<Node<T>>>,
}
impl<T> List<T> {
#!/bin/bash
#
# A script that identifies the root of the current rustc checkout.
# If the environment variable RUST_ROOT is not set, then it
# walks up from the current directory to find the right spot.
if [ -n "$RUST_ROOT" ]; then
echo "$RUST_ROOT"
exit 0
fi
use std::comm::{Port, Chan};
enum Event {
Pos(int, int),
}
fn main() {
let (port, chan) = Chan::new();
spawn(proc() handle_events(port));
run_event_loop(chan);