Created
September 1, 2021 09:11
-
-
Save kiwiyou/815ed2c74741ac744ed4ab06e49b4916 to your computer and use it in GitHub Desktop.
Rust Fast I/O
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
fn main() { | |
let buf = stdin(); | |
let mut token = buf.split_ascii_whitespace(); | |
use std::fmt::Write; | |
// buf.clear(); | |
let mut buf = String::new(); | |
writeln!(buf, "{}", token.next().unwrap()).unwrap(); | |
print!("{}", buf); | |
} | |
extern "C" { | |
fn mmap(addr: usize, len: usize, p: i32, f: i32, fd: i32, o: i64) -> *mut u8; | |
fn fstat(fd: i32, stat: *mut usize) -> i32; | |
} | |
fn stdin() -> &'static str { | |
let mut stat = [0; 18]; | |
unsafe { fstat(0, (&mut stat).as_mut_ptr()) }; | |
let buffer = unsafe { mmap(0, stat[6], 1, 2, 0, 0) }; | |
unsafe { std::str::from_utf8_unchecked(std::slice::from_raw_parts(buffer, stat[6])) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment