Updated function to retrieve text file content
This commit is contained in:
+26
-2
@@ -1,8 +1,13 @@
|
|||||||
|
|
||||||
pub mod parser {
|
pub mod parser {
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead, BufReader};
|
||||||
|
|
||||||
pub struct SomeObject {
|
pub struct SomeObject {
|
||||||
pub value: String
|
pub value: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct NumberParser {
|
pub struct NumberParser {
|
||||||
pub filepath: String
|
pub filepath: String
|
||||||
}
|
}
|
||||||
@@ -13,13 +18,26 @@ pub mod parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn filedump(&self) -> Vec<SomeObject> {
|
pub fn filedump(&self) -> Vec<SomeObject> {
|
||||||
let objs: Vec<SomeObject> = Vec::new();
|
let mut objs: Vec<SomeObject> = Vec::new();
|
||||||
|
|
||||||
|
if let Ok(lines) = self.read_lines(&self.filepath) {
|
||||||
|
for line in lines {
|
||||||
|
if let Ok(phonenumber) = line {
|
||||||
|
let myobj: SomeObject = SomeObject {
|
||||||
|
value: phonenumber
|
||||||
|
};
|
||||||
|
|
||||||
|
objs.push(myobj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn updatevalues(&self, vals: Vec<SomeObject>) -> Vec<SomeObject> {
|
pub fn updatevalues(&self, vals: Vec<SomeObject>) -> Vec<SomeObject> {
|
||||||
let updated: Vec<SomeObject> = Vec::new();
|
let mut updated: Vec<SomeObject> = vals;
|
||||||
|
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,5 +53,11 @@ pub mod parser {
|
|||||||
pub fn save_file(&self, vals: Vec<SomeObject>) {
|
pub fn save_file(&self, vals: Vec<SomeObject>) {
|
||||||
println!("Hi");
|
println!("Hi");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn read_lines(&self, filename: &str) -> std::io::Result<std::io::Lines<std::io::BufReader<std::fs::File>>> {
|
||||||
|
let file = std::fs::File::open(filename)?;
|
||||||
|
Ok(std::io::BufReader::new(file).lines())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user