Refactor db/batch matching
Remove the TODO; refactor matching to correctly handle conditionally built `Sled` variants. Use `unreachable` instead of `unimplemented` with a comment hinting that this is a bug, this makes it explicit, both at runtime and when reading the code, that this match arm should not be hit.
This commit is contained in:
parent
343e97da0e
commit
0e6add0cfb
@ -312,24 +312,17 @@ impl BatchDatabase for AnyDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn commit_batch(&mut self, batch: Self::Batch) -> Result<(), Error> {
|
fn commit_batch(&mut self, batch: Self::Batch) -> Result<(), Error> {
|
||||||
// TODO: refactor once `move_ref_pattern` is stable
|
|
||||||
#[allow(irrefutable_let_patterns)]
|
|
||||||
match self {
|
match self {
|
||||||
AnyDatabase::Memory(db) => {
|
AnyDatabase::Memory(db) => match batch {
|
||||||
if let AnyBatch::Memory(batch) = batch {
|
AnyBatch::Memory(batch) => db.commit_batch(batch),
|
||||||
db.commit_batch(batch)
|
#[cfg(feature = "key-value-db")]
|
||||||
} else {
|
_ => unimplemented!("Sled batch shouldn't be used with Memory db."),
|
||||||
unimplemented!()
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(feature = "key-value-db")]
|
#[cfg(feature = "key-value-db")]
|
||||||
AnyDatabase::Sled(db) => {
|
AnyDatabase::Sled(db) => match batch {
|
||||||
if let AnyBatch::Sled(batch) = batch {
|
AnyBatch::Sled(batch) => db.commit_batch(batch),
|
||||||
db.commit_batch(batch)
|
_ => unimplemented!("Memory batch shouldn't be used with Sled db."),
|
||||||
} else {
|
},
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user