Search
 
SCRIPT & CODE EXAMPLE
 

RUST

read line rust

use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

fn main() {
    // File hosts must exist in current path before this produces output
    if let Ok(lines) = read_lines("./hosts") {
        // Consumes the iterator, returns an (Optional) String
        for line in lines {
            if let Ok(ip) = line {
                println!("{}", ip);
            }
        }
    }
}

// The output is wrapped in a Result to allow matching on errors
// Returns an Iterator to the Reader of the lines of the file.
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where P: AsRef<Path>, {
    let file = File::open(filename)?;
    Ok(io::BufReader::new(file).lines())
}
Comment

PREVIOUS NEXT
Code Example
Rust :: sleep in rust 
Rust :: rust error handling 
Rust :: rust in a string, replace multiple spaces with single space 
Rust :: rust vec to array 
Rust :: rust new vec 
Rust :: armanriazi•rust•concept•superpowers 
Rust :: read file in rust bufreader 
Rust :: count matches with regex 
Rust :: rustlang char array 
Rust :: rust compiler 
Rust :: Rust Multithreading with a Vector of different functions 
Rust :: armanriazi•rust•reference•vs•pointer 
Rust :: rust named tuple 
Rust :: armanriazi•rust•error•error[E0382]: borrow of moved value: `val` ... thread 
Rust :: armanriazi•rust•error•E0615•attempted to take value of method `collect` on type 
Rust :: armanriazi•rust•smartpointer•deref•coercion 
Rust :: armanriazi•rust•error•[E0072]: recursive type `List` has infinite size -- src/main.rs:3:1 | 3 | enum List { | ^^^^^^^^^ recursive type has infinite size 
Rust :: rust•armanriazi•refactor 
Lua :: how to execute scripts when a button gui is pressed roblox 
Lua :: roblox player joined 
Lua :: roblox interpolate color 
Lua :: roblox table.find 
Lua :: how to make a color changing brick in roblox studio 
Lua :: lua list of all keys 
Lua :: lua string to date 
Lua :: delete part on touch roblox 
Lua :: Lua how to get the index of a nested table 
Lua :: how to make a run in roblox lua 
Lua :: Lua how to comment 
Matlab :: matlab complex numbers 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =