#[non_exhaustive]pub enum FindError {
NotFound,
Ambiguous {
count: usize,
first: usize,
},
}Expand description
Why find_one did not return an offset.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Implementations§
Source§impl FindError
impl FindError
Sourcepub fn reason(&self) -> &'static str
pub fn reason(&self) -> &'static str
A stable, machine-readable reason: "not-found" or "ambiguous".
Every error type in this crate carries one, so a caller can branch on
the cause without matching variants it would have to update when a new
one appears (these enums are #[non_exhaustive] precisely so that new
ones can appear).
§Labelling a failure
There is deliberately no context or label on this type. A
&'static str would not take a label built at run time, and a String
would make the error allocate on a path that is often in a loop. Both
fields a caller needs to write its own message are public, so the
wrapper this replaces is one line:
use thumb_asm::{find_one, FindError, Needle};
let image = [0u8; 8];
let what = "cmac table";
let msg = match find_one(&image, Needle::Word(0xdead_beef)) {
Ok(at) => format!("{what} at {at:#x}"),
Err(e @ FindError::Ambiguous { count, .. }) => {
format!("{what} signature matched {count} times ({e})")
}
Err(e) => format!("{what}: {e}"),
};
assert_eq!(msg, "cmac table: no match");Trait Implementations§
impl Copy for FindError
impl Eq for FindError
Source§impl Error for FindError
impl Error for FindError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
impl StructuralPartialEq for FindError
Auto Trait Implementations§
impl Forget for FindError
impl Freeze for FindError
impl RefUnwindSafe for FindError
impl Send for FindError
impl Sync for FindError
impl Unpin for FindError
impl UnsafeUnpin for FindError
impl UnwindSafe for FindError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more