Uses "let else" syntax where relevant

pull/559/head
Tpt 1 year ago committed by Thomas Tanon
parent 5085a60a87
commit cb9922379c
  1. 7
      lib/oxttl/src/toolkit/parser.rs
  2. 6
      lib/oxttl/src/trig.rs
  3. 6
      lib/sparesults/src/csv.rs
  4. 39
      lib/src/storage/backend/fallback.rs
  5. 32
      lib/src/storage/backend/rocksdb.rs
  6. 8
      testsuite/src/manifest.rs

@ -99,11 +99,10 @@ impl<RR: RuleRecognizer> Parser<RR> {
} }
} }
if self.lexer.is_end() { if self.lexer.is_end() {
if let Some(state) = self.state.take() { let Some(state) = self.state.take() else {
state.recognize_end(&mut self.results, &mut self.errors)
} else {
return None; return None;
} };
state.recognize_end(&mut self.results, &mut self.errors)
} else { } else {
return None; return None;
} }

@ -570,11 +570,9 @@ fn is_turtle_decimal(value: &str) -> bool {
while value.first().map_or(false, u8::is_ascii_digit) { while value.first().map_or(false, u8::is_ascii_digit) {
value = &value[1..]; value = &value[1..];
} }
if let Some(v) = value.strip_prefix(b".") { let Some(value) = value.strip_prefix(b".") else {
value = v;
} else {
return false; return false;
} };
!value.is_empty() && value.iter().all(u8::is_ascii_digit) !value.is_empty() && value.iter().all(u8::is_ascii_digit)
} }

@ -230,11 +230,9 @@ fn is_turtle_decimal(value: &str) -> bool {
while value.first().map_or(false, u8::is_ascii_digit) { while value.first().map_or(false, u8::is_ascii_digit) {
value = &value[1..]; value = &value[1..];
} }
if let Some(v) = value.strip_prefix(b".") { let Some(value) = value.strip_prefix(b".") else {
value = v;
} else {
return false; return false;
} };
!value.is_empty() && value.iter().all(u8::is_ascii_digit) !value.is_empty() && value.iter().all(u8::is_ascii_digit)
} }

@ -129,9 +129,7 @@ impl Reader {
let data: Vec<_> = match &self.0 { let data: Vec<_> = match &self.0 {
InnerReader::Simple(reader) => { InnerReader::Simple(reader) => {
let trees = reader.read().unwrap(); let trees = reader.read().unwrap();
let tree = if let Some(tree) = trees.get(column_family) { let Some(tree) = trees.get(column_family) else {
tree
} else {
return Ok(Iter { return Ok(Iter {
iter: Vec::new().into_iter(), iter: Vec::new().into_iter(),
current: None, current: None,
@ -147,28 +145,25 @@ impl Reader {
} }
} }
InnerReader::Transaction(reader) => { InnerReader::Transaction(reader) => {
if let Some(reader) = reader.upgrade() { let Some(reader) = reader.upgrade() else {
let trees = (*reader).borrow();
let tree = if let Some(tree) = trees.get(column_family) {
tree
} else {
return Ok(Iter {
iter: Vec::new().into_iter(),
current: None,
});
};
if prefix.is_empty() {
tree.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
} else {
tree.range(prefix.to_vec()..)
.take_while(|(k, _)| k.starts_with(prefix))
.map(|(k, v)| (k.clone(), v.clone()))
.collect()
}
} else {
return Err(StorageError::Other( return Err(StorageError::Other(
"The transaction is already ended".into(), "The transaction is already ended".into(),
)); ));
};
let trees = (*reader).borrow();
let Some(tree) = trees.get(column_family) else {
return Ok(Iter {
iter: Vec::new().into_iter(),
current: None,
});
};
if prefix.is_empty() {
tree.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
} else {
tree.range(prefix.to_vec()..)
.take_while(|(k, _)| k.starts_with(prefix))
.map(|(k, v)| (k.clone(), v.clone()))
.collect()
} }
} }
}; };

@ -941,19 +941,18 @@ impl Reader {
)) ))
} }
InnerReader::Transaction(inner) => { InnerReader::Transaction(inner) => {
if let Some(inner) = inner.upgrade() { let Some(inner) = inner.upgrade() else {
ffi_result!(rocksdb_transaction_get_pinned_cf_with_status( return Err(StorageError::Other(
*inner, "The transaction is already ended".into(),
self.options, ));
column_family.0, };
key.as_ptr().cast(), ffi_result!(rocksdb_transaction_get_pinned_cf_with_status(
key.len() *inner,
)) self.options,
} else { column_family.0,
return Err(StorageError::Other( key.as_ptr().cast(),
"The transaction is already ended".into(), key.len()
)); ))
}
} }
InnerReader::PlainDb(inner) => { InnerReader::PlainDb(inner) => {
ffi_result!(rocksdb_get_pinned_cf_with_status( ffi_result!(rocksdb_get_pinned_cf_with_status(
@ -1022,13 +1021,12 @@ impl Reader {
rocksdb_transactiondb_create_iterator_cf(inner.db.db, options, column_family.0) rocksdb_transactiondb_create_iterator_cf(inner.db.db, options, column_family.0)
} }
InnerReader::Transaction(inner) => { InnerReader::Transaction(inner) => {
if let Some(inner) = inner.upgrade() { let Some(inner) = inner.upgrade() else {
rocksdb_transaction_create_iterator_cf(*inner, options, column_family.0)
} else {
return Err(StorageError::Other( return Err(StorageError::Other(
"The transaction is already ended".into(), "The transaction is already ended".into(),
)); ));
} };
rocksdb_transaction_create_iterator_cf(*inner, options, column_family.0)
} }
InnerReader::PlainDb(inner) => { InnerReader::PlainDb(inner) => {
rocksdb_create_iterator_cf(inner.db, options, column_family.0) rocksdb_create_iterator_cf(inner.db, options, column_family.0)

@ -84,9 +84,7 @@ impl TestManifest {
fn next_test(&mut self) -> Result<Option<Test>> { fn next_test(&mut self) -> Result<Option<Test>> {
loop { loop {
let test_node = if let Some(test_node) = self.tests_to_do.pop_front() { let Some(test_node) = self.tests_to_do.pop_front() else {
test_node
} else {
return Ok(None); return Ok(None);
}; };
let test_node = if let Term::NamedNode(test_node) = test_node { let test_node = if let Term::NamedNode(test_node) = test_node {
@ -273,9 +271,7 @@ impl TestManifest {
} }
fn load_next_manifest(&mut self) -> Result<Option<()>> { fn load_next_manifest(&mut self) -> Result<Option<()>> {
let url = if let Some(url) = self.manifests_to_do.pop_front() { let Some(url) = self.manifests_to_do.pop_front() else {
url
} else {
return Ok(None); return Ok(None);
}; };
self.graph.clear(); self.graph.clear();

Loading…
Cancel
Save