add db::Writer::load
This commit is contained in:
parent
3b24a1be2f
commit
f51f2be18f
13
src/db.rs
13
src/db.rs
@ -79,6 +79,7 @@ where
|
||||
_t: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn push(&mut self, item: T) -> Result<(), String> {
|
||||
let pos: LSize = self.data_buf.position() as LSize;
|
||||
|
||||
@ -102,6 +103,18 @@ where
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load<I>(&mut self, iter: &mut I) -> Result<(), String>
|
||||
where
|
||||
I: Iterator<Item = T>,
|
||||
{
|
||||
for item in iter {
|
||||
self.push(item)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn finish(mut self) -> Result<(), String> {
|
||||
// finish tab
|
||||
let pos: LSize = self.data_buf.position() as LSize;
|
||||
|
10
src/main.rs
10
src/main.rs
@ -269,16 +269,16 @@ fn db_writer2_task(rx: mpsc::Receiver<Question>) {
|
||||
db::Writer::new(NEW_DB_FILENAME, writer_opts).expect("new db writer");
|
||||
|
||||
let mut num = 1;
|
||||
rx.into_iter().for_each(|mut q| {
|
||||
let mut iter = rx.iter().map(|mut q| {
|
||||
q.num = num;
|
||||
num += 1;
|
||||
q
|
||||
});
|
||||
|
||||
writer
|
||||
.push(q)
|
||||
.load(&mut iter)
|
||||
.unwrap_or_else(|e| panic!("db writer push, num={num}, {e:#?}"));
|
||||
|
||||
num += 1;
|
||||
});
|
||||
|
||||
writer.finish().expect("db writer finish");
|
||||
|
||||
println!("write done");
|
||||
|
Loading…
Reference in New Issue
Block a user