-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is needed for caching rendering results.
- Loading branch information
Showing
12 changed files
with
171 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::error; | ||
use std::fmt; | ||
|
||
/// An error that can be cloned. | ||
pub trait ErrorClone: error::Error + Send + Sync + 'static { | ||
/// Clone the error. | ||
fn clone_box(&self) -> Box<ErrorClone>; | ||
} | ||
|
||
impl<E> ErrorClone for E | ||
where | ||
E: error::Error + Clone + Send + Sync + 'static, | ||
{ | ||
fn clone_box(&self) -> Box<ErrorClone> { | ||
Box::new(self.clone()) | ||
} | ||
} | ||
|
||
impl Clone for Box<ErrorClone> { | ||
fn clone(&self) -> Box<ErrorClone> { | ||
self.clone_box() | ||
} | ||
} | ||
|
||
/// A lossy way to have any error be clonable. | ||
#[derive(Debug, Clone)] | ||
pub struct CloneableError { | ||
error: String, | ||
} | ||
|
||
impl CloneableError { | ||
/// Lossily make any error cloneable. | ||
pub fn new<E>(error: E) -> Self | ||
where | ||
E: error::Error + Send + Sync + 'static, | ||
{ | ||
Self { | ||
error: error.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for CloneableError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
writeln!(f, "{}", self.error) | ||
} | ||
} | ||
|
||
impl error::Error for CloneableError { | ||
fn description(&self) -> &str { | ||
self.error.as_str() | ||
} | ||
|
||
fn cause(&self) -> Option<&error::Error> { | ||
None | ||
} | ||
} |
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 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 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
Oops, something went wrong.