Skip to content

Commit

Permalink
Replace custom ResultExt with stable Result::inspect_err (#951)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Carl Jones <djonesoa@amazon.com>
  • Loading branch information
dannycjones committed Aug 1, 2024
1 parent 387ad79 commit 0732770
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
3 changes: 1 addition & 2 deletions mountpoint-s3-crt/src/io/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::common::task_scheduler::{Task, TaskScheduler, TaskStatus};
use crate::io::futures::FutureSpawner;
use crate::io::io_library_init;
use crate::CrtError as _;
use crate::ResultExt;

/// An event loop that can be used to schedule and execute tasks
#[derive(Debug)]
Expand Down Expand Up @@ -122,7 +121,7 @@ impl EventLoopGroup {
let inner = unsafe {
aws_event_loop_group_new_default(allocator.inner.as_ptr(), max_threads, &shutdown_options)
.ok_or_last_error()
.on_err(|| abort_shutdown_callback(shutdown_options))?
.inspect_err(|_| abort_shutdown_callback(shutdown_options))?
};

Ok(Self { inner })
Expand Down
22 changes: 0 additions & 22 deletions mountpoint-s3-crt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,6 @@ impl CrtError for i32 {
}
}

/// Workaround until Result::inspect_err is stable.
pub(crate) trait ResultExt: Sized {
fn on_err<F>(self, f: F) -> Self
where
F: FnOnce();
}

impl<T, E> ResultExt for Result<T, E> {
fn on_err<F>(self, f: F) -> Result<T, E>
where
F: FnOnce(),
{
match self {
Ok(val) => Ok(val),
Err(err) => {
f();
Err(err)
}
}
}
}

#[cfg(test)]
mod test {
use crate::common::rust_log_adapter::RustLogAdapter;
Expand Down
4 changes: 2 additions & 2 deletions mountpoint-s3-crt/src/s3/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::http::request_response::{Headers, Message};
use crate::io::channel_bootstrap::ClientBootstrap;
use crate::io::retry_strategy::RetryStrategy;
use crate::s3::s3_library_init;
use crate::{aws_byte_cursor_as_slice, CrtError, ResultExt, ToAwsByteCursor};
use crate::{aws_byte_cursor_as_slice, CrtError, ToAwsByteCursor};
use futures::Future;
use mountpoint_s3_crt_sys::*;

Expand Down Expand Up @@ -812,7 +812,7 @@ impl Client {
.ok_or_last_error()
// Drop the options Box if we failed to make the meta request.
// Assumption: CRT won't call shutdown callback if make_meta_request returns null.
.on_err(|| std::mem::drop(Box::from_raw(options)))?;
.inspect_err(|_| std::mem::drop(Box::from_raw(options)))?;

Ok(MetaRequest { inner })
}
Expand Down

0 comments on commit 0732770

Please sign in to comment.