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,
|
_t: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, item: T) -> Result<(), String> {
|
pub fn push(&mut self, item: T) -> Result<(), String> {
|
||||||
let pos: LSize = self.data_buf.position() as LSize;
|
let pos: LSize = self.data_buf.position() as LSize;
|
||||||
|
|
||||||
@ -102,6 +103,18 @@ where
|
|||||||
|
|
||||||
Ok(())
|
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> {
|
pub fn finish(mut self) -> Result<(), String> {
|
||||||
// finish tab
|
// finish tab
|
||||||
let pos: LSize = self.data_buf.position() as LSize;
|
let pos: LSize = self.data_buf.position() as LSize;
|
||||||
|
12
src/main.rs
12
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");
|
db::Writer::new(NEW_DB_FILENAME, writer_opts).expect("new db writer");
|
||||||
|
|
||||||
let mut num = 1;
|
let mut num = 1;
|
||||||
rx.into_iter().for_each(|mut q| {
|
let mut iter = rx.iter().map(|mut q| {
|
||||||
q.num = num;
|
q.num = num;
|
||||||
|
|
||||||
writer
|
|
||||||
.push(q)
|
|
||||||
.unwrap_or_else(|e| panic!("db writer push, num={num}, {e:#?}"));
|
|
||||||
|
|
||||||
num += 1;
|
num += 1;
|
||||||
|
q
|
||||||
});
|
});
|
||||||
|
|
||||||
|
writer
|
||||||
|
.load(&mut iter)
|
||||||
|
.unwrap_or_else(|e| panic!("db writer push, num={num}, {e:#?}"));
|
||||||
|
|
||||||
writer.finish().expect("db writer finish");
|
writer.finish().expect("db writer finish");
|
||||||
|
|
||||||
println!("write done");
|
println!("write done");
|
||||||
|
Loading…
Reference in New Issue
Block a user