mirror of
https://github.com/jht5945/finding.git
synced 2025-12-28 21:50:04 +08:00
move to local_util
This commit is contained in:
@@ -1,10 +1,46 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
cell::Cell,
|
||||||
fs::File,
|
fs::File,
|
||||||
path::Path,
|
path::Path,
|
||||||
io::prelude::*,
|
io::prelude::*,
|
||||||
};
|
};
|
||||||
use rust_util::{ XResult, new_box_error, };
|
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> {
|
pub fn read_file_content<P: AsRef<Path>>(p: P, len_of_large_file: u64) -> XResult<String> {
|
||||||
let file = p.as_ref();
|
let file = p.as_ref();
|
||||||
if !file.exists() {
|
if !file.exists() {
|
||||||
|
|||||||
47
src/main.rs
47
src/main.rs
@@ -6,7 +6,7 @@ extern crate rust_util;
|
|||||||
mod opt;
|
mod opt;
|
||||||
mod local_util;
|
mod local_util;
|
||||||
|
|
||||||
use std::{ cell::Cell, path::Path, time::SystemTime, };
|
use std::{ path::Path, time::SystemTime, };
|
||||||
use opt::*;
|
use opt::*;
|
||||||
use rust_util::{
|
use rust_util::{
|
||||||
iff,
|
iff,
|
||||||
@@ -16,51 +16,16 @@ use rust_util::{
|
|||||||
util_size::*,
|
util_size::*,
|
||||||
util_msg::*,
|
util_msg::*,
|
||||||
};
|
};
|
||||||
use local_util::read_file_content;
|
use local_util::{
|
||||||
|
CountCell,
|
||||||
|
MatchLine,
|
||||||
|
read_file_content,
|
||||||
|
};
|
||||||
|
|
||||||
const EMPTY: &str = "";
|
const EMPTY: &str = "";
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
const GIT_HASH: &str = env!("GIT_HASH");
|
const GIT_HASH: &str = env!("GIT_HASH");
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct MatchLine {
|
|
||||||
line_number: usize,
|
|
||||||
line_string: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MatchLine {
|
|
||||||
fn new(line_number: usize, line_string: String) -> MatchLine {
|
|
||||||
MatchLine { line_number, line_string, }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CountCell {
|
|
||||||
cell: Cell<u64>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CountCell {
|
|
||||||
fn new() -> CountCell {
|
|
||||||
CountCell {
|
|
||||||
cell: Cell::new(0_u64)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn get(&self) -> u64 {
|
|
||||||
self.cell.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn add(&self, i: u64) {
|
|
||||||
self.cell.set(self.cell.get() + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn add_one(&self) {
|
|
||||||
self.add(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_version(options: &Options) {
|
fn print_version(options: &Options) {
|
||||||
println!(r#"finding {} - {}
|
println!(r#"finding {} - {}
|
||||||
Copyright (C) 2019-2020 Hatter Jiang.
|
Copyright (C) 2019-2020 Hatter Jiang.
|
||||||
|
|||||||
Reference in New Issue
Block a user