Skip to content

Instantly share code, notes, and snippets.

🦀
Rustacean

Steve Klabnik steveklabnik

🦀
Rustacean
Block or report user

Report or block steveklabnik

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@steveklabnik
steveklabnik / vectorlinkedlist.rs
Created Sep 7, 2018
yeah, it's a linked list with indices in a vector
View vectorlinkedlist.rs
#[derive(Debug)]
pub struct IndexList<T> {
contents: Vec<Option<Entry<T>>>,
}
#[derive(Debug)]
pub struct Entry<T> {
item: T,
next: Option<usize>,
prev: Option<usize>,
@steveklabnik
steveklabnik / linkedlist.rs
Created Sep 5, 2018
yeah it's a linked list
View linkedlist.rs
use std::ptr;
pub struct DoubleLinkedList<T> {
head: *mut Entry<T>,
tail: *mut Entry<T>,
}
pub struct Entry<T> {
item: T,
next: *mut Entry<T>,
View main.rs
#![feature(lang_items, start)]
#![no_std]
#[link(name = "c")]
extern {
fn puts(s: *const u8) -> isize;
fn abort() -> !;
}
#[lang = "panic_fmt"]
View add.rs
#![feature(lang_items)]
#![no_std]
#[no_mangle]
pub fn add_one(x: i32) -> i32 {
x + 1
}
// needed for no_std
@steveklabnik
steveklabnik / main.rs
Created Oct 25, 2017
The Results of the Expressive C++17 Coding Challenge in Rust
View main.rs
use std::env;
use std::io;
use std::io::prelude::*;
use std::fs::File;
#[derive(Debug)]
enum Error {
Io(io::Error),
Program(&'static str),
}
View boot.asm
global start
section .text
bits 32
start:
; Point the first entry of the level 4 page table to the first entry in the
; p3 table
mov eax, p3_table
or eax, 0b11 ;
mov dword [p4_table + 0], eax
@steveklabnik
steveklabnik / passes.txt
Created May 9, 2017
-Z time-passes for sparkles
View passes.txt
Compiling sparkles v0.1.0 (file:///C:/Users/steve/src/sparkles)
time: 0.003; rss: 17MB parsing
time: 0.000; rss: 17MB recursion limit
time: 0.000; rss: 17MB crate injection
time: 0.000; rss: 17MB plugin loading
time: 0.000; rss: 17MB plugin registration
time: 0.241; rss: 89MB expansion
time: 0.000; rss: 89MB maybe building test harness
time: 0.000; rss: 89MB maybe creating a macro crate
time: 0.000; rss: 89MB checking for inline asm in case the target doesn't support it
View looping.rs
pub fn sum_loop(nums: &[i32]) -> i32 {
let mut s = 0;
for i in nums {
s = s + i;
}
s
}
View mutable references
fn add_to_mutable_reference(x: &mut i32) {
*x +=1;
}
#[test]
fn mutable_reference_test() {
let mut x = 5;
let y = &mut x;
mutable_reference(y);
You can’t perform that action at this time.