This file contains 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 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; |
This file contains 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
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 |
This file contains 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
#!/usr/bin/env sh | |
# Usage: | |
# | |
# $ rustinstant 'println!("hello world!")' | |
# => hello world | |
# | |
# or | |
# | |
# $ cat << EOF | rustinstant |
This file contains 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
#!/usr/bin/env sh | |
# $ ./rust-temporary-exec.sh 'println!("hello world!")' | |
# => hello world! | |
set -eu | |
echo "fn main() { $1 }" | rustc - && ./rust_out |
This file contains 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
#![feature(test)] | |
extern crate test; | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use std::str; | |
use test::Bencher; |
This file contains 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
trait Foo { | |
fn method(&self) -> String; | |
} | |
impl Foo for u8 { | |
fn method(&self) -> String { | |
format!("u8: {}", *self) | |
} | |
} |
This file contains 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
#[derive(Clone, Debug)] | |
struct AnyOption { | |
a: bool, | |
b: bool, | |
} | |
struct AnyBuilder { | |
option: AnyOption, | |
} |
This file contains 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
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); |
This file contains 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
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; |
This file contains 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
#!/usr/bin/env sh | |
# Scrap web pages | |
# | |
# Usage: | |
# $ ./wscrap.sh https:xxx/xxx/ | |
set -eu | |
DEPTH=8 |