mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Make read_i64_from private and merge read_str_from to its caller
Also remove duplicated read_i64_from. Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
18
src/lib.rs
18
src/lib.rs
@@ -219,7 +219,13 @@ mod sealed {
|
||||
}
|
||||
|
||||
fn get(&self, key: &str) -> Result<String> {
|
||||
self.open_path(key, false).and_then(read_str_from)
|
||||
self.open_path(key, false).and_then(|mut file: File| {
|
||||
let mut string = String::new();
|
||||
match file.read_to_string(&mut string) {
|
||||
Ok(_) => Ok(string.trim().to_owned()),
|
||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -827,7 +833,7 @@ pub fn nested_keyed_to_hashmap(mut file: File) -> Result<HashMap<String, HashMap
|
||||
}
|
||||
|
||||
/// read and parse an i64 data
|
||||
pub fn read_i64_from(mut file: File) -> Result<i64> {
|
||||
fn read_i64_from(mut file: File) -> Result<i64> {
|
||||
let mut string = String::new();
|
||||
match file.read_to_string(&mut string) {
|
||||
Ok(_) => string
|
||||
@@ -837,11 +843,3 @@ pub fn read_i64_from(mut file: File) -> Result<i64> {
|
||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_str_from(mut file: File) -> Result<String> {
|
||||
let mut string = String::new();
|
||||
match file.read_to_string(&mut string) {
|
||||
Ok(_) => Ok(string.trim().to_owned()),
|
||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use std::sync::mpsc::Receiver;
|
||||
use crate::error::ErrorKind::*;
|
||||
use crate::error::*;
|
||||
use crate::events;
|
||||
use crate::read_i64_from;
|
||||
|
||||
use crate::flat_keyed_to_hashmap;
|
||||
|
||||
@@ -880,17 +881,6 @@ fn read_u64_from(mut file: File) -> Result<u64> {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_i64_from(mut file: File) -> Result<i64> {
|
||||
let mut string = String::new();
|
||||
match file.read_to_string(&mut string) {
|
||||
Ok(_) => string
|
||||
.trim()
|
||||
.parse()
|
||||
.map_err(|e| Error::with_cause(ParseError, e)),
|
||||
Err(e) => Err(Error::with_cause(ReadFailed, e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn read_string_from(mut file: File) -> Result<String> {
|
||||
let mut string = String::new();
|
||||
match file.read_to_string(&mut string) {
|
||||
|
||||
Reference in New Issue
Block a user