Change all remaining exception related wording

This commit is contained in:
David Tolnay 2019-10-04 23:44:16 -04:00
parent 68dcc845e9
commit 94d944c9e0
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 13 additions and 13 deletions

View File

@ -20,7 +20,7 @@ pub struct Error {
} }
impl Error { impl Error {
/// Create a new exception from any error type. /// Create a new error object from any error type.
/// ///
/// The error type must be threadsafe and `'static`, so that the `Error` will be as well. /// The error type must be threadsafe and `'static`, so that the `Error` will be as well.
/// ///
@ -64,12 +64,12 @@ impl Error {
} }
} }
/// View this exception as the underlying error. /// View this error object as the underlying error.
pub fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) { pub fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
&**self &**self
} }
/// View this exception as the underlying error, mutably. /// View this error object as the underlying error, mutably.
pub fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) { pub fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
&mut **self &mut **self
} }
@ -82,25 +82,25 @@ impl Error {
.backtrace .backtrace
.as_ref() .as_ref()
.or_else(|| self.inner.error().backtrace()) .or_else(|| self.inner.error().backtrace())
.expect("exception backtrace capture failed") .expect("backtrace capture failed")
} }
/// An iterator of errors contained by this Error. /// An iterator of errors contained by this Error.
/// ///
/// This iterator will visit every error in the "cause chain" of this exception, beginning with /// This iterator will visit every error in the "cause chain" of this error object, beginning with
/// the error that this exception was created from. /// the error that this error object was created from.
pub fn errors(&self) -> Errors<'_> { pub fn errors(&self) -> Errors<'_> {
Errors { Errors {
next: Some(self.inner.error()), next: Some(self.inner.error()),
} }
} }
/// Returns `true` if `E` is the type wrapped by this exception. /// Returns `true` if `E` is the type wrapped by this error object.
pub fn is<E: Display + Debug + Send + Sync + 'static>(&self) -> bool { pub fn is<E: Display + Debug + Send + Sync + 'static>(&self) -> bool {
TypeId::of::<E>() == self.inner.type_id TypeId::of::<E>() == self.inner.type_id
} }
/// Attempt to downcast the exception to a concrete type. /// Attempt to downcast the error object to a concrete type.
pub fn downcast<E: Display + Debug + Send + Sync + 'static>(self) -> Result<E, Error> { pub fn downcast<E: Display + Debug + Send + Sync + 'static>(self) -> Result<E, Error> {
if let Some(error) = self.downcast_ref::<E>() { if let Some(error) = self.downcast_ref::<E>() {
unsafe { unsafe {
@ -114,7 +114,7 @@ impl Error {
} }
} }
/// Downcast this exception by reference. /// Downcast this error object by reference.
pub fn downcast_ref<E: Display + Debug + Send + Sync + 'static>(&self) -> Option<&E> { pub fn downcast_ref<E: Display + Debug + Send + Sync + 'static>(&self) -> Option<&E> {
if self.is::<E>() { if self.is::<E>() {
unsafe { Some(&*(self.inner.error() as *const dyn StdError as *const E)) } unsafe { Some(&*(self.inner.error() as *const dyn StdError as *const E)) }
@ -123,7 +123,7 @@ impl Error {
} }
} }
/// Downcast this exception by mutable reference. /// Downcast this error object by mutable reference.
pub fn downcast_mut<E: Display + Debug + Send + Sync + 'static>(&mut self) -> Option<&mut E> { pub fn downcast_mut<E: Display + Debug + Send + Sync + 'static>(&mut self) -> Option<&mut E> {
if self.is::<E>() { if self.is::<E>() {
unsafe { Some(&mut *(self.inner.error_mut() as *mut dyn StdError as *mut E)) } unsafe { Some(&mut *(self.inner.error_mut() as *mut dyn StdError as *mut E)) }
@ -277,12 +277,12 @@ mod repr_correctness {
use std::mem; use std::mem;
#[test] #[test]
fn size_of_exception() { fn size_of_error() {
assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>()); assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>());
} }
#[allow(dead_code)] #[allow(dead_code)]
fn assert_exception_autotraits() fn assert_error_autotraits()
where where
Error: Unpin + Send + Sync + 'static, Error: Unpin + Send + Sync + 'static,
{ {

View File

@ -18,7 +18,7 @@ macro_rules! bail {
}; };
} }
/// Construct an ad-hoc exception from a string. /// Construct an ad-hoc error from a string.
/// ///
/// This evaluates to an `Error`. It can take either just a string, or a format string with /// This evaluates to an `Error`. It can take either just a string, or a format string with
/// arguments. It also can take any custom type which implements `Debug` and `Display`. /// arguments. It also can take any custom type which implements `Debug` and `Display`.