for_each_record

Function for_each_record 

Source
pub fn for_each_record<F>(text: &str, f: F)
where F: FnMut(&str),
Expand description

对记录进行流式处理,并对每条记录调用回调而不分配 Vec。

这是处理日志文本时分配最少的方式。该函数会遍历所有记录,对每条记录调用回调函数, 但不分配任何 Vec 来存储记录。

§参数

  • text - 完整的日志文本
  • f - 对每条记录调用的回调函数

§示例

use dm_database_parser_sqllog::for_each_record;

let log_text = r#"..."#;
for_each_record(log_text, |rec| {
    println!("记录: {}", rec.lines().next().unwrap_or(""));
});