1
0
mirror of https://github.com/jht5945/finding.git synced 2025-12-28 05:30:04 +08:00

move to local_util

This commit is contained in:
2020-05-01 22:16:52 +08:00
parent 204e82635a
commit ca8a3fb848
2 changed files with 42 additions and 41 deletions

View File

@@ -1,10 +1,46 @@
use std::{
cell::Cell,
fs::File,
path::Path,
io::prelude::*,
};
use rust_util::{ XResult, new_box_error, };
#[derive(Debug)]
pub struct MatchLine {
pub line_number: usize,
pub line_string: String,
}
impl MatchLine {
pub fn new(line_number: usize, line_string: String) -> MatchLine {
MatchLine { line_number, line_string, }
}
}
pub struct CountCell( Cell<u64> );
impl CountCell {
pub fn new() -> CountCell {
CountCell( Cell::new(0_u64) )
}
#[inline]
pub fn get(&self) -> u64 {
self.0.get()
}
#[inline]
pub fn add(&self, i: u64) {
self.0.set(self.0.get() + i);
}
#[inline]
pub fn add_one(&self) {
self.add(1);
}
}
pub fn read_file_content<P: AsRef<Path>>(p: P, len_of_large_file: u64) -> XResult<String> {
let file = p.as_ref();
if !file.exists() {