|
@@ -2,7 +2,7 @@ use std::error::Error;
|
|
|
use std::fmt::Debug;
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
-#[derive(Debug, Clone)]
|
|
|
+#[derive(Debug, Clone, PartialEq)]
|
|
|
/// An error that can occur when trying to borrow a value.
|
|
|
pub enum BorrowError {
|
|
|
/// The value was dropped.
|
|
@@ -22,7 +22,7 @@ impl Display for BorrowError {
|
|
|
|
|
|
impl Error for BorrowError {}
|
|
|
|
|
|
-#[derive(Debug, Clone)]
|
|
|
+#[derive(Debug, Clone, PartialEq)]
|
|
|
/// An error that can occur when trying to borrow a value mutably.
|
|
|
pub enum BorrowMutError {
|
|
|
/// The value was dropped.
|
|
@@ -46,12 +46,23 @@ impl Display for BorrowMutError {
|
|
|
impl Error for BorrowMutError {}
|
|
|
|
|
|
/// An error that can occur when trying to use a value that has been dropped.
|
|
|
-#[derive(Debug, Copy, Clone)]
|
|
|
+#[derive(Debug, Copy, Clone, PartialEq)]
|
|
|
pub struct ValueDroppedError {
|
|
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
|
|
pub(crate) created_at: &'static std::panic::Location<'static>,
|
|
|
}
|
|
|
|
|
|
+impl ValueDroppedError {
|
|
|
+ /// Create a new `ValueDroppedError`.
|
|
|
+ #[allow(unused)]
|
|
|
+ pub fn new(created_at: &'static std::panic::Location<'static>) -> Self {
|
|
|
+ Self {
|
|
|
+ #[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
|
|
+ created_at,
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
impl Display for ValueDroppedError {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
f.write_str("Failed to borrow because the value was dropped.")?;
|
|
@@ -64,12 +75,23 @@ impl Display for ValueDroppedError {
|
|
|
impl std::error::Error for ValueDroppedError {}
|
|
|
|
|
|
/// An error that can occur when trying to borrow a value that has already been borrowed mutably.
|
|
|
-#[derive(Debug, Copy, Clone)]
|
|
|
+#[derive(Debug, Copy, Clone, PartialEq)]
|
|
|
pub struct AlreadyBorrowedMutError {
|
|
|
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
|
|
pub(crate) borrowed_mut_at: &'static std::panic::Location<'static>,
|
|
|
}
|
|
|
|
|
|
+impl AlreadyBorrowedMutError {
|
|
|
+ /// Create a new `AlreadyBorrowedMutError`.
|
|
|
+ #[allow(unused)]
|
|
|
+ pub fn new(borrowed_mut_at: &'static std::panic::Location<'static>) -> Self {
|
|
|
+ Self {
|
|
|
+ #[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
|
|
+ borrowed_mut_at,
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
impl Display for AlreadyBorrowedMutError {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
f.write_str("Failed to borrow because the value was already borrowed mutably.")?;
|
|
@@ -82,12 +104,23 @@ impl Display for AlreadyBorrowedMutError {
|
|
|
impl std::error::Error for AlreadyBorrowedMutError {}
|
|
|
|
|
|
/// An error that can occur when trying to borrow a value mutably that has already been borrowed immutably.
|
|
|
-#[derive(Debug, Clone)]
|
|
|
+#[derive(Debug, Clone, PartialEq)]
|
|
|
pub struct AlreadyBorrowedError {
|
|
|
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
|
|
pub(crate) borrowed_at: Vec<&'static std::panic::Location<'static>>,
|
|
|
}
|
|
|
|
|
|
+impl AlreadyBorrowedError {
|
|
|
+ /// Create a new `AlreadyBorrowedError`.
|
|
|
+ #[allow(unused)]
|
|
|
+ pub fn new(borrowed_at: Vec<&'static std::panic::Location<'static>>) -> Self {
|
|
|
+ Self {
|
|
|
+ #[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
|
|
+ borrowed_at,
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
impl Display for AlreadyBorrowedError {
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
f.write_str("Failed to borrow mutably because the value was already borrowed immutably.")?;
|