Skip to content

Commit

Permalink
Merge pull request #183 from flipperzero-rs/status-err-or-else
Browse files Browse the repository at this point in the history
Change `Status::err_or_else` to use `Fn(i32) -> T`
  • Loading branch information
dcoles authored Oct 29, 2024
2 parents d3a15f0 + 76f5761 commit eec1208
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

- `flipperzero::dialogs::DialogFileBrowserOptions` now uses native initialization function.
- `flipperzero::time::Duration::MAX` is now the maximum duration representable.
- `sys::furi::Status::err_or_else` now takes a `Fn(i32) -> T` closure.

### Removed

Expand Down
6 changes: 3 additions & 3 deletions crates/flipperzero/src/furi/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<LockState> for i32 {
pub fn lock() -> furi::Result<LockState> {
let status = sys::furi::Status::from(unsafe { sys::furi_kernel_lock() });

status.err_or_else(|status| status.0.into())
status.err_or_else(LockState::from)
}

/// Unlock kernel, resume process scheduling.
Expand All @@ -60,7 +60,7 @@ pub fn lock() -> furi::Result<LockState> {
pub fn unlock() -> furi::Result<LockState> {
let status = sys::furi::Status::from(unsafe { sys::furi_kernel_unlock() });

status.err_or_else(|status| status.0.into())
status.err_or_else(LockState::from)
}

/// Restore kernel lock state.
Expand All @@ -71,7 +71,7 @@ pub fn unlock() -> furi::Result<LockState> {
pub fn restore_lock(state: LockState) -> furi::Result<LockState> {
let status = sys::furi::Status::from(unsafe { sys::furi_kernel_restore_lock(state.into()) });

status.err_or_else(|status| status.0.into())
status.err_or_else(LockState::from)
}

/// Return kernel tick frequency in hertz.
Expand Down
4 changes: 2 additions & 2 deletions crates/sys/src/furi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ impl Status {
}

/// Returns `Err(Status)` if [`Status`] is an error, otherwise `Ok(or_else(Status))`.
pub fn err_or_else<T>(self, or_else: impl Fn(Self) -> T) -> Result<T, Self> {
pub fn err_or_else<T>(self, or_else: impl Fn(i32) -> T) -> Result<T, Self> {
if self.is_err() {
Err(self)
} else {
Ok(or_else(self))
Ok(or_else(self.0))
}
}
}
Expand Down

0 comments on commit eec1208

Please sign in to comment.