Instantly share code, notes, and snippets.

View tuple-like_struct_impl_FnOnce.rs
use std::io;
#[derive(Debug)]
/// tuple-like struct
struct Foo(i32);
fn num(n: i32) -> io::Result<i32> {
Ok(n)
}
View linux.rs
use std::fs::File;
use std::io::{self, Seek, SeekFrom};
use std::time::Duration;
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use mio;
use mio::unix::{EventedFd, UnixReady};
use nix::poll::{self, PollFd, EventFlags};
use libc::c_int;
use super::*;
use inotify;
View mio_stdin.rs
extern crate mio;
use mio::unix::EventedFd;
use mio::{Token, PollOpt, Ready, Poll, Events};
use std::io::ErrorKind;
use std::time::Duration;
fn main() {
const IN: Token = Token(0);
let fd0_e = EventedFd(&0);
View ttyin.rs
extern crate nix;
use std::io;
use std::io::BufRead;
/// switch stdin to key input
fn ttyin() -> io::Result<()> {
use std::fs::File;
use nix::unistd;
use std::os::unix::io::AsRawFd;
View zero_size_struct.rs
use std::marker::PhantomData;
use std::mem;
// Unit-like struct
struct U;
// Empty tuple struct
struct T();
// Empty struct
struct E {}
// Empty tuple member struct
View rustinstant
#!/usr/bin/env sh
# Usage:
#
# $ rustinstant 'println!("hello world!")'
# => hello world
#
# or
#
# $ cat << EOF | rustinstant
View rust-temporary-exec.sh
#!/usr/bin/env sh
# $ ./rust-temporary-exec.sh 'println!("hello world!")'
# => hello world!
set -eu
echo "fn main() { $1 }" | rustc - && ./rust_out
View bench_starts_with.rs
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use super::*;
use std::str;
use test::Bencher;
View trait_dispatch.rs
trait Foo {
fn method(&self) -> String;
}
impl Foo for u8 {
fn method(&self) -> String {
format!("u8: {}", *self)
}
}
View builder.rs
#[derive(Clone, Debug)]
struct AnyOption {
a: bool,
b: bool,
}
struct AnyBuilder {
option: AnyOption,
}