1 extern crate unicode_segmentation; 2 3 use std::error::Error; 4 use std::io::{self, BufRead, Write}; 5 6 use unicode_segmentation::UnicodeSegmentation; 7 main() -> Result<(), Box<dyn Error>>8fn main() -> Result<(), Box<dyn Error>> { 9 let stdin = io::stdin(); 10 let mut stdin = stdin.lock(); 11 let mut stdout = io::BufWriter::new(io::stdout()); 12 13 let mut line = String::new(); 14 while stdin.read_line(&mut line)? > 0 { 15 let end = line 16 .grapheme_indices(true) 17 .map(|(start, g)| start + g.len()) 18 .take(10) 19 .last() 20 .unwrap_or(line.len()); 21 #[allow(deprecated)] // for Rust 1.28.0 22 stdout.write_all(line[..end].trim_right().as_bytes())?; 23 stdout.write_all(b"\n")?; 24 25 line.clear(); 26 } 27 Ok(()) 28 } 29