Skip to content

Instantly share code, notes, and snippets.

View luqmana's full-sized avatar

Luqman Aden luqmana

View GitHub Profile
@luqmana
luqmana / gist:2d688d81fed84caba0a6
Created May 2, 2014 05:16
Ident Server in Rust

Simple Ident Server in Rust

This is a quick example of a simple TCP server written (mostly) in Rust which implements RFC 1413. It has a bit of networking, regex, and FFI.

All code examples have been written against a recent build from git: rustc 0.11-pre (9f484e6 2014-04-30 15:46:47 -0700)

To start off, how about we flesh out the general structure a little:

@luqmana
luqmana / rqsrt.rs
Last active December 16, 2015 15:39
fn libc_rsqrt(f: &f32) -> f32 {
1.0/f32::sqrt(*f)
}
fn llvm_rsqrt(f: &f32) -> f32 {
1.0/core::unstable::intrinsics::sqrtf32(*f)
}
fn asm_rsqrt(f: &f32) -> f32 {
let mut b = &0.0f32;
unsafe {
asm!("rsqrtss ($0), %xmm0\n\t\
struct Point {
x: int,
y: int
}
trait Positioned {
fn x(&self)-> int;
fn y(&self)-> int;
fn setX(&mut self, int);
fn setY(&mut self, int);
diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs
index 049063f..38fb55f 100644
--- a/src/librustc/mir/repr.rs
+++ b/src/librustc/mir/repr.rs
@@ -294,7 +294,7 @@ impl<'tcx> Terminator<'tcx> {
}
}
-#[derive(Debug, RustcEncodable, RustcDecodable)]
+#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
struct Parent;
impl Parent {
fn new_child<'a>(&'a self) -> Child<'a> {
Child {
parent: self
}
}
}
; ModuleID = 'rust.rc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%tydesc = type { i64, i64, void ({}*, i8*)*, void ({}*, i8*)*, void ({}*, i8*)*, void ({}*, i8*)* }
%enum.ValidUsage = type { i64, i64, [0 x i8] }
%enum.Action = type { i64, void (%enum.ValidUsage*, { i64, %tydesc*, i8*, i8*, i8 }*, { { i64, i64, [0 x i8] }**, i64 }*)*, [16 x i8] }
%str_slice = type { i8*, i64 }
%enum.UsageSource = type { i64, %str_slice, [0 x i8] }
%"enum.std::libc::types::common::c95::c_void[#1]" = type {}
fn find_fn(ccx: @mut CrateContext, fn_id: ast::node_id) -> Option<codemap::span> {
match ccx.tcx.def_map.find(&fn_id) {
Some(&ast::def_fn(def_id, _)) => {
if ast_util::is_local(def_id) {
match ccx.tcx.items.find(&def_id.node) {
Some(&ast_map::node_item(item, _)) => {
match item.node {
ast::item_fn(*) => Some(item.span),
_ => None
fn main() {
let b = test_nd_dr(8, 3);
assert_eq!(b, 2);
}
fn test_nd_dr(n: i8, d: i8) -> i8 {
let separate_div_rem = (n / d, n % d);
let combined_div_rem = n.div_rem(&d);
let (_, b) = separate_div_rem;
use std::cell::Cell;
use std::rt::io::net::tcp::TcpListener;
use std::rt::io::net::ip::Ipv4;
use std::rt::io::{Listener, Writer};
fn main() {
let mut listener = TcpListener::bind(Ipv4(0, 0, 0, 0, 6767))
.expect("Unable to bind to 0.0.0.0:6767");
loop {
@luqmana
luqmana / hashmap-macro.rs
Last active December 21, 2015 00:28
A macro to easily create and populate hash maps.
#![feature(macro_rules)]
extern crate collections;
use collections::HashMap;
// A macro to easily create and populate hash maps
macro_rules! hashmap(
{ $($key:expr => $value:expr),+ } => {
{