Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
SiegeLord / output
Last active November 2, 2019 18:59
Rust matrix moving
clone
move
move
Matrix { data: [100, 200, 300] }
@SiegeLord
SiegeLord / matrix.rs
Created June 3, 2014 23:05
Auto-ref woes
#[deriving(Show)]
struct Matrix
{
data: Vec<f32>
}
trait ToMat
{
fn to_mat(self) -> Matrix;
}
use std::io;
fn main()
{
match io::stdin().read_line().unwrap().as_slice().trim()
{
"abc" => println!("def"),
_ => ()
}
}
@SiegeLord
SiegeLord / errors
Created May 21, 2014 18:09
Borrowcheck woes
test3.rs:106:63: 106:71 error: lifetime of `comp_set` is too short to guarantee its contents can be safely reborrowed
test3.rs:106 self.get_comp_idx(Component::get_type(None::<T>)).map(|idx| comp_set.get_mut(idx))
^~~~~~~~
test3.rs:105:2: 115:3 note: `comp_set` would have to be valid for the lifetime &'l as defined on the block at 105:1...
test3.rs:105 {
test3.rs:106 self.get_comp_idx(Component::get_type(None::<T>)).map(|idx| comp_set.get_mut(idx))
test3.rs:107
test3.rs:108 /*
test3.rs:109 match self.get_comp_idx(Component::get_type(None::<T>))
test3.rs:110 {
@SiegeLord
SiegeLord / Makefile
Created May 15, 2014 16:41
Simple makefile
all: main
main: main.rs Makefile
rustc --opt-level 3 --dep-info $@.dep -L ~/lib -g $<
-include main.dep
.PHONY: clean
clean:
--- out.ll 2014-05-12 13:20:11.501655442 -0400
+++ in.ll 2014-05-12 13:20:06.781655392 -0400
@@ -1,9 +1,8 @@
-; Function Attrs: uwtable
-define internal void @_ZN4test3bug20hf04dd765537e803c3Ua4v0.0E(%struct.Vector* nocapture) unnamed_addr #1 {
+; Function Attrs: inlinehint uwtable
+define internal void @_ZN4test14vec_speed_vec212closure.2554E(i8*) unnamed_addr #2 {
entry-block:
%fmt.i = alloca %"struct.std::fmt::Arguments[#1]"*
%num = alloca %str_slice
@SiegeLord
SiegeLord / new.ll
Last active August 29, 2015 14:01
Benchmark regression
; ModuleID = 'algebloat.rs'
target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"struct.core::intrinsics::TypeId[#3]" = type { i64 }
%str_slice = type { i8*, i64 }
%"struct.test::Bencher[#5]" = type { i64, i64, i64, i64 }
%"struct.std::fmt::Arguments[#1]" = type { { %"enum.std::fmt::rt::Piece[#1]"*, i64 }, { %"struct.std::fmt::Argument[#1]"*, i64 } }
%"enum.std::fmt::rt::Piece[#1]" = type { i8, [7 x i8], [9 x i64] }
%"struct.std::fmt::Argument[#1]" = type { void (%"enum.core::result::Result<(),std::io::IoError>[#3]"*, %"enum.core::any::Void[#3]"*, %"struct.std::fmt::Formatter[#1]"*)*, %"enum.core::any::Void[#3]"* }
@SiegeLord
SiegeLord / test.rs
Last active August 29, 2015 14:00
IndexAssign
use std::cell::Cell;
trait IndexAssign<IDX, RHS>
{
fn index_assign(self, idx: IDX, rhs: RHS);
}
struct ArrayLike
{
arr: Vec<Cell<u32>>
@SiegeLord
SiegeLord / match.rs
Created April 26, 2014 15:36
Sweet match
match (mine_left, mine_right, mine_up, mine_down)
{
(true, _, _, _) => world.mine(player.x, player.y, -1, 0),
(_, true, _, _) => world.mine(player.x, player.y, 1, 0),
(_, _, true, _) => world.mine(player.x, player.y, 0, -1),
(_, _, _, true) => world.mine(player.x, player.y, 0, 1),
_ => ()
}
@SiegeLord
SiegeLord / test.rs
Created April 24, 2014 17:01
Closure
test.rs:5:2: 5:6 error: closure invocation in a `&` reference
test.rs:5 (*a)();
^~~~
error: aborting due to previous error