Skip to content

Instantly share code, notes, and snippets.

@ryochack
ryochack / linux.rs
Last active September 16, 2018 14:23
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;
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);
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;
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
#!/usr/bin/env sh
# Usage:
#
# $ rustinstant 'println!("hello world!")'
# => hello world
#
# or
#
# $ cat << EOF | rustinstant
#!/usr/bin/env sh
# $ ./rust-temporary-exec.sh 'println!("hello world!")'
# => hello world!
set -eu
echo "fn main() { $1 }" | rustc - && ./rust_out
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use super::*;
use std::str;
use test::Bencher;
trait Foo {
fn method(&self) -> String;
}
impl Foo for u8 {
fn method(&self) -> String {
format!("u8: {}", *self)
}
}
#[derive(Clone, Debug)]
struct AnyOption {
a: bool,
b: bool,
}
struct AnyBuilder {
option: AnyOption,
}
use std::io;
use std::fs::File;
fn main() {
let r = io::stdin();
let mut reader = r.lock();
let mut writer = File::create("temp_copy.txt").unwrap();
let _ = io::copy(&mut reader, &mut writer);