1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
extern crate hostname; use std::io::{self, BufRead}; use hostname::get_hostname; fn input() -> std::string::String { let mut line = String::new(); let stdin = io::stdin(); stdin.lock().read_line(&mut line); return line; } pub fn sensor(name: std::string::String, f: &Fn() -> std::string::String) { loop { let line = input(); if line == "quit\n" { break; } println!("{}:{}:{}", get_hostname().unwrap(), name, f()); println!("end"); } }