This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn movement_example_2() { | |
let x = 5.0f64; | |
let y = x; | |
assert_eq!(y,x); //Test Passed | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn movement_example_1() { | |
let x = Type::default(); | |
let y = x; | |
assert_eq!(y,x); //COMPILER ERROR! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Notice this type DERIVES Copy? | |
//that means this type will Copy, not move. | |
#[derive(Copy)] | |
pub struct CopyExample { | |
pub data: u64, | |
pub other_data: u32 | |
} | |
fn move_example() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct Foo { | |
key: String, | |
value: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
html "golang.org/x/net/html" | |
atom "golang.org/x/net/html/atom" | |
"net/http" | |
"os" | |
"regexp" | |
"strings" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate json; | |
use json::JsonValue; | |
use json::object::Object; | |
use std::iter::Iterator; | |
enum Output<'a> { | |
Nothing, | |
Obj(&'a JsonValue), | |
Val(u64) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate libc; | |
use libc::{socket,setsockopt,bind,mmap,SOCK_DGRAM, PF_PACKET}; | |
use std::io::{self, Error}; | |
const ETH_P_IP: i32 = 0x0800i32; | |
//Open The Socket | |
pub fn open_raw_ip_socket() -> io::Result<i32> { | |
let socket_type: i32 = SOCK_DGRAM; | |
//socket_type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct tpacket_req { | |
unsigned int tp_block_size; /* Minimal size of contiguous block */ | |
unsigned int tp_block_nr; /* Number of blocks */ | |
unsigned int tp_frame_size; /* Size of frame */ | |
unsigned int tp_frame_nr; /* Total number of frames */ | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[repr(C)] // <- tells Rust to treat this structure like its C | |
pub struct Tpacket { | |
block_size: u32, | |
block_number: u32, | |
frame_size: u32, | |
frame_number: u32 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tp_block_size= 4096 | |
tp_frame_size= 2048 | |
tp_block_nr = 4 | |
tp_frame_nr = 8 | |
we will get the following buffer structure: | |
block #1 block #2 | |
+---------+---------+ +---------+---------+ |
OlderNewer