aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_get.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2020-11-11 16:38:56 +0100
committerAlex <alex@adnab.me>2020-11-11 16:38:56 +0100
commitb00e29f931dcfe79b766e2c5b2c9ddb5f6a2f200 (patch)
treee0e8e02ddaed445ec331342c2b4328829accd889 /src/api/s3_get.rs
parent045009da9b7ac4198574bd5aa256c11cfe4ae469 (diff)
parent7d7b9e95a9b7fe71e7bb42b08a22698475a9c78c (diff)
downloadgarage-b00e29f931dcfe79b766e2c5b2c9ddb5f6a2f200.tar.gz
garage-b00e29f931dcfe79b766e2c5b2c9ddb5f6a2f200.zip
Merge pull request 'Option Type: replace pattern matching by the corresponding syntaxic sugar' (#13) from feature/syntaxic-sugar into master
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/13
Diffstat (limited to 'src/api/s3_get.rs')
-rw-r--r--src/api/s3_get.rs35
1 files changed, 11 insertions, 24 deletions
diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs
index 71c656f2..a68c485b 100644
--- a/src/api/s3_get.rs
+++ b/src/api/s3_get.rs
@@ -41,25 +41,20 @@ pub async fn handle_head(
bucket: &str,
key: &str,
) -> Result<Response<Body>, Error> {
- let object = match garage
+ let object = garage
.object_table
.get(&bucket.to_string(), &key.to_string())
.await?
- {
- None => return Err(Error::NotFound),
- Some(o) => o,
- };
+ .ok_or(Error::NotFound)?;
- let version = match object
+ let version = object
.versions()
.iter()
.rev()
.filter(|v| v.is_data())
.next()
- {
- Some(v) => v,
- None => return Err(Error::NotFound),
- };
+ .ok_or(Error::NotFound)?;
+
let version_meta = match &version.state {
ObjectVersionState::Complete(ObjectVersionData::Inline(meta, _)) => meta,
ObjectVersionState::Complete(ObjectVersionData::FirstBlock(meta, _)) => meta,
@@ -80,25 +75,20 @@ pub async fn handle_get(
bucket: &str,
key: &str,
) -> Result<Response<Body>, Error> {
- let object = match garage
+ let object = garage
.object_table
.get(&bucket.to_string(), &key.to_string())
.await?
- {
- None => return Err(Error::NotFound),
- Some(o) => o,
- };
+ .ok_or(Error::NotFound)?;
- let last_v = match object
+ let last_v = object
.versions()
.iter()
.rev()
.filter(|v| v.is_complete())
.next()
- {
- Some(v) => v,
- None => return Err(Error::NotFound),
- };
+ .ok_or(Error::NotFound)?;
+
let last_v_data = match &last_v.state {
ObjectVersionState::Complete(x) => x,
_ => unreachable!(),
@@ -146,10 +136,7 @@ pub async fn handle_get(
let get_next_blocks = garage.version_table.get(&last_v.uuid, &EmptyKey);
let (first_block, version) = futures::try_join!(read_first_block, get_next_blocks)?;
- let version = match version {
- Some(v) => v,
- None => return Err(Error::NotFound),
- };
+ let version = version.ok_or(Error::NotFound)?;
let mut blocks = version
.blocks()