Skip to content

Instantly share code, notes, and snippets.

View Noxivs's full-sized avatar

Noxivs Noxivs

  • Toulouse, France
View GitHub Profile
#![feature(core)]
#![feature(io)]
use std::io;
use std::mem;
struct Int64 {
pub low: u32,
pub high: u32,
}
pub trait Protocol {
type Clean = Self;
}
impl Protocol for usize {
type Clean = usize;
}
impl Protocol for IdentificationBaseMessage {
type Clean = IdentificationBaseMessage;
#![feature(macro_rules)]
macro_rules! grammar(
($name:expr,$x:expr) => ( /* parser + generate function */)
)
grammar!("url", "
rule TOP {
<protocol>'://'<address>
}
pub struct HelloConnectMessage {
salt: String,
key: Vec<u8>
}
impl HelloConnectMessage {
pub fn salt<'a>(&self) -> &'a String {
&self.salt
}
#[handler="3"]
pub fn handle_hello_connect(client: Client, cx: Context, msg: ClientMessage) {
/* ... */
}
#[deriving(Clone)]
pub type Handler = fn(client: Client, cx: Context, msg: ClientMessage) -> ();
use std::ascii::{AsciiCast, AsciiStr};
use std::comm::TryRecvError;
use std::io::net::tcp::TcpStream;
static NEW_LINE_CHAR: u8 = 0x0a;
static END_LINE_CHAR: u8 = 0x00;
static MAX_BUFFER_LENGHT: uint = 8192;
#![feature(quote)]
extern crate syntax;
extern crate rustc;
use std::collections::HashMap;
use std::hash::Hash;
use std::gc::{Gc, GC};
use std::io::{MemReader, MemWriter,IoResult, IoError, InvalidInput};
trait StringReader {
fn read_le_string(&mut self) -> IoResult<String>;
}
impl StringReader for MemReader {
fn read_le_string(&mut self) -> IoResult<String> {
let str_b_len = self.read_le_u16();
match str_b_len {
@Noxivs
Noxivs / tree.rs
Last active August 29, 2015 14:03
/// # Example
///
/// ```rust
/// fn main() {
/// let mut tree = Tree::<char,String>::new();
/// tree.insert_recursively(&vec!('H', 'C'), "HandleHelloConnectMessage".into_string());
/// tree.insert_recursively(&vec!('H', 'G'), "HandleHelloGameMessage".into_string());
///
/// println!("{}", tree.find_recursively(&vec!('H', 'G')).unwrap());
/// println!("{}", tree.find_recursively(&vec!('H', 'C')).unwrap());
extern crate time;
use std::io::{Listener, Acceptor};
use std::io::net::tcp::{TcpListener};
use std::io::net::ip::{SocketAddr, Ipv4Addr};
use std::io::timer;
static TICK_TIME: i32 = 60; //ms
fn tick(last_tick: &mut i32) {