Skip to content

Instantly share code, notes, and snippets.

View mstewartgallus's full-sized avatar
🏳️‍⚧️
Trans

Ms. Molly Stewart-Gallus mstewartgallus

🏳️‍⚧️
Trans
View GitHub Profile
@mstewartgallus
mstewartgallus / Backtrace
Last active December 16, 2015 06:38
Rust Compiler Error Log
#0 upcall_fail (expr=0x7fffe4a8f670 "explicit failure",
file=0x7fffe490a320 "/home/steven/desktop/others/sources/rust/src/libsyntax/diagnostic.rs", line=99) at /home/steven/desktop/others/sources/rust/src/rt/rust_upcall.cpp:120
#1 0x00007ffff79cd6db in sys::begin_unwind_::_9873ff47b9982218::_07pre ()
from /usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#2 0x00007ffff79cd682 in sys::begin_unwind::anon::anon::expr_fn_14822 ()
from /usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
@mstewartgallus
mstewartgallus / buggy.rs
Created April 17, 2013 18:34
Rust Compiler Fails to properly compile data structures that contain static lists
struct T (&'static [int]);
static t : T = T (&'static [5, 4, 3]);
fn main () {
io::println (fmt! ("%?", t));
}
@mstewartgallus
mstewartgallus / array.rs
Last active December 16, 2015 09:38
Arrays as nonprimitive
// A typical example of idiomatic Rust code ;)
use core::cast;
use core::sys;
#[packed]
pub struct Cons <H, T> { head : H, tail : T }
#[packed]
pub struct Nil;
macro_rules! list (
@mstewartgallus
mstewartgallus / tree.rs
Created April 18, 2013 23:57
SiegeLords Tree
struct Node<'self>
{
Valid : bool,
Parent : Option<&'self Node<'self>>
}
impl<'self> Node<'self>
{
fn new() -> Node<'self>
{
@mstewartgallus
mstewartgallus / oneshot.rs
Created April 21, 2013 04:13
Buggy OneShot Function Implementation
// Rust lacks closures that can only be used once so they are emulated here.
priv trait OneShot <T> {
fn run (~self) -> T;
}
priv struct AnonymousOneShot <S, T> (S, ~fn (S) -> T);
impl <S, T> OneShot <T> for AnonymousOneShot <S, T> {
fn run (~self) -> T {
let ~AnonymousOneShot (x, f) = self;
f (x)
@mstewartgallus
mstewartgallus / vector.rs
Created April 27, 2013 00:43
Buggy matrix math code.
use core::num::*;
use std::complex::*;
use core::ops::*;
pub struct Vector { x : f32, y : f32 }
pub impl Vector {
fn from_scalar (scalar : f32) -> Vector { Vector { x : scalar, y : scalar } }
fn normal_to (vector : Vector) -> Vector {
Vector { x : -vector.y, y : vector.x }
}
pub trait Introspectable {
fn size (&self) -> uint;
fn raw_data (&self) -> ~[u8];
fn debug_info (&self) -> ~str;
}
impl <T> Introspectable for T {
fn size (&self) -> uint { sys::size_of:: <T> () }
fn raw_data (&self) -> ~[u8] {
@mstewartgallus
mstewartgallus / assets.rs
Created May 15, 2013 21:02
A large file of arrays that can not be easily processed by rustc
#[link (
name = "assets",
vers = "0.0")];
pub struct Sprite {
indices : ~[[u16, ..3]]
}
pub struct SpriteList {
@mstewartgallus
mstewartgallus / gadts.rs
Last active November 2, 2019 18:59
Gadts in Rust
/// This type is only every inhabited when S is nominally equivalent to T
pub type Is <S, T> = Is_ <S, T>;
priv struct Is_ <S, T>;
// Construct a proof of the fact that a type is nominally equivalent
// to itself.
pub fn Is <T> () -> Is <T, T> { Is_ }
pub impl <S, T> Is_ <S, T> {
@mstewartgallus
mstewartgallus / nonmoveable.rs
Created May 19, 2013 05:08
A prototype for a nonmoveable type.
/// A data type for making a type which is not moveable by
/// default. This is useful for marking large types which are
/// expensive to copy around.
pub struct NonMoveable<'self> {
/// Never actually used but only for guaranteeing certain
/// properties by default
priv contents: &'self()
}
pub fn NonMoveable<T>(f : &fn(NonMoveable) -> T) -> T {