diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-11-11 16:12:42 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-11-11 16:12:42 +0100 |
commit | 5a5592c176c7a17f143d0f221b6495808b7f4054 (patch) | |
tree | e368b58121f4ae5822528e54d4d8ded8c2eb2dba /src/api/s3_get.rs | |
parent | 045009da9b7ac4198574bd5aa256c11cfe4ae469 (diff) | |
download | garage-5a5592c176c7a17f143d0f221b6495808b7f4054.tar.gz garage-5a5592c176c7a17f143d0f221b6495808b7f4054.zip |
Replace with option syntaxic sugar
Diffstat (limited to 'src/api/s3_get.rs')
-rw-r--r-- | src/api/s3_get.rs | 35 |
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() |