Skip to content

Instantly share code, notes, and snippets.

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);
use std::io::{self, Read, Write};
use std::fs::File;
fn copy(reader: &mut Read, writer: &mut Write) {
const BUFFER_SIZE: usize = 32 * 1024;
let mut buf = [0u8; BUFFER_SIZE];
while let Ok(n) = reader.read(&mut buf) {
if n == 0 {
break;
#!/usr/bin/env sh
# Scrap web pages
#
# Usage:
# $ ./wscrap.sh https:xxx/xxx/
set -eu
DEPTH=8