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 let Some(state) = self.state.take() {
state.recognize_end(&mut self.results, &mut self.errors)
} else {
let Some(state) = self.state.take() else {
return None;
}
};
state.recognize_end(&mut self.results, &mut self.errors)
} else {
return None;
}

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

@ -129,9 +129,7 @@ impl Reader {
let data: Vec<_> = match &self.0 {
InnerReader::Simple(reader) => {
let trees = reader.read().unwrap();
let tree = if let Some(tree) = trees.get(column_family) {
tree
} else {
let Some(tree) = trees.get(column_family) else {
return Ok(Iter {
iter: Vec::new().into_iter(),
current: None,
@ -147,28 +145,25 @@ impl Reader {
}
}
InnerReader::Transaction(reader) => {
if let Some(reader) = reader.upgrade() {
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 {
let Some(reader) = reader.upgrade() else {
return Err(StorageError::Other(
"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) => {
if let Some(inner) = inner.upgrade() {
ffi_result!(rocksdb_transaction_get_pinned_cf_with_status(
*inner,
self.options,
column_family.0,
key.as_ptr().cast(),
key.len()
))
} else {
return Err(StorageError::Other(
"The transaction is already ended".into(),
));
}
let Some(inner) = inner.upgrade() else {
return Err(StorageError::Other(
"The transaction is already ended".into(),
));
};
ffi_result!(rocksdb_transaction_get_pinned_cf_with_status(
*inner,
self.options,
column_family.0,
key.as_ptr().cast(),
key.len()
))
}
InnerReader::PlainDb(inner) => {
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)
}
InnerReader::Transaction(inner) => {
if let Some(inner) = inner.upgrade() {
rocksdb_transaction_create_iterator_cf(*inner, options, column_family.0)
} else {
let Some(inner) = inner.upgrade() else {
return Err(StorageError::Other(
"The transaction is already ended".into(),
));
}
};
rocksdb_transaction_create_iterator_cf(*inner, options, column_family.0)
}
InnerReader::PlainDb(inner) => {
rocksdb_create_iterator_cf(inner.db, options, column_family.0)

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

Loading…
Cancel
Save