Skip to content

Instantly share code, notes, and snippets.

View kracekumar's full-sized avatar

Kracekumar kracekumar

View GitHub Profile
fn return_none() -> Option<bool>{
None
}
fn main(){
println!("{:?}", return_none().unwrap());
}
// Output

user@user-ThinkPad-T400 ~/c/imon> cargo --explain E0117

This error indicates a violation of one of Rust's orphan rules for trait implementations. The rule prohibits any implementation of a foreign trait (a trait defined in another crate) where

  • the type that is implementing the trait is foreign
  • all of the parameters being passed to the trait (if there are any) are also foreign.
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> src/db.rs:26:1
|
26 | impl FromSql for chrono::Date<UTC> {
| ^ impl doesn't use types inside crate
|
= note: the impl does not reference any types defined in this crate
fn fn1(){
assert!(true, true);
}
fn fn2(){
panic!(true, false);
}
fn main(){
fn1();
fn main() {
let signal = chan_signal::notify(&[Signal::INT, Signal::TERM]);
let (sdone, rdone) = chan::sync(0);
thread::spawn(move || run(sdone)); // run function will be killed as soon interrupt is received.
chan_select! {
signal.recv() -> signal => {
println!("received signal: {:?}", signal)
},
rdone.recv() => {
println!("Program completed normally.");
#[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)]
struct Custom {
id: u32,
key: String,
}
struct Traffic {
/* Traffic structure reflects `traffic` table columns and
used for serialization and deserialization */
id: i32,
domain_name: String,
data_consumed_in_bytes: i64,
date: chrono::Date<UTC>,
created_at: time::Timespec,
updated_at: time::Timespec,
@kracekumar
kracekumar / spelling_mistake_catch.txt
Created October 25, 2016 15:48
Good error message
user@user-ThinkPad-T400 ~/c/imon> sudo ~/.cargo/bin/cargo run --bin imon -- start
Compiling imon v0.1.0 (file:///home/user/code/imon)
error[E0425]: unresolved name `payload`. Did you mean `paylod`?
--> src/cli.rs:91:29
|
91 | decode_ipv4_packet(&payload);
| ^^^^^^^
error: aborting due to previous error
@kracekumar
kracekumar / curio.txt
Created October 17, 2016 05:59
Curio Monitor
user@user-ThinkPad-T400 ~/c/bt> python -m curio.monitor
Curio Monitor: 9 tasks running
Type help for commands
curio > ps
Task State Cycles Timeout Task
------ ------------ ---------- ------- --------------------------------------------------
1 FUTURE_WAIT 2 None Monitor.monitor_task
2 TASK_JOIN 8 None download
@kracekumar
kracekumar / chrome-cache-parser-output
Created August 19, 2016 10:46
chrome-cache-parser-output
krace@Kracekumars-MacBook-Pro ~/c/snippets> cat view-http-cache.htm | python2.7 chrome-cache-parser.py
651
3
9
30
2331
3
21
1545
3