-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from cunarist/rinf-error-types
Return `RinfError` on errors
- Loading branch information
Showing
15 changed files
with
177 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
flutter_ffi_plugin/example/native/sample_crate/src/error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::error::Error; | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
pub struct ExampleError(pub Box<dyn Error + Send + Sync>); | ||
|
||
impl fmt::Display for ExampleError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let source = self.0.as_ref(); | ||
write!(f, "An error occured inside the example code.\n{source}") | ||
} | ||
} | ||
|
||
impl Error for ExampleError { | ||
fn source(&self) -> Option<&(dyn Error + 'static)> { | ||
Some(self.0.as_ref()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::error::Error; | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
pub enum RinfError { | ||
LockDartIsolate, | ||
NoDartIsolate, | ||
BuildRuntime, | ||
LockMessageChannel, | ||
NoMessageChannel, | ||
MessageReceiverTaken, | ||
DecodeMessage, | ||
NoSignalHandler, | ||
} | ||
|
||
impl fmt::Display for RinfError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
RinfError::LockDartIsolate => { | ||
write!(f, "Could not acquire the Dart isolate lock.") | ||
} | ||
RinfError::NoDartIsolate => { | ||
write!(f, "Dart isolate for Rust signals was not created.") | ||
} | ||
RinfError::BuildRuntime => { | ||
write!(f, "Could not build the tokio runtime.") | ||
} | ||
RinfError::LockMessageChannel => { | ||
write!(f, "Could not acquire the message channel lock.") | ||
} | ||
RinfError::NoMessageChannel => { | ||
write!(f, "Message channel was not created.",) | ||
} | ||
RinfError::MessageReceiverTaken => { | ||
write!(f, "Each Dart signal receiver can be taken only once.") | ||
} | ||
RinfError::DecodeMessage => { | ||
write!(f, "Could not decode the message.") | ||
} | ||
RinfError::NoSignalHandler => { | ||
write!(f, "Could not find the handler for Dart signal.") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Error for RinfError {} |
Oops, something went wrong.