-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow conversion from ColoredString to Error (#86)
- Loading branch information
1 parent
2b886a5
commit 884232e
Showing
3 changed files
with
40 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extern crate colored; | ||
|
||
use colored::Colorize; | ||
use std::error::Error; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
Err("ERROR".red())? | ||
} |
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,24 @@ | ||
use super::ColoredString; | ||
use std::{error::Error, fmt}; | ||
|
||
pub struct ColoredStringError(pub ColoredString); | ||
|
||
impl ColoredStringError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.0.to_string()) | ||
} | ||
} | ||
|
||
impl fmt::Display for ColoredStringError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.fmt(f) | ||
} | ||
} | ||
|
||
impl fmt::Debug for ColoredStringError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.fmt(f) | ||
} | ||
} | ||
|
||
impl Error for ColoredStringError {} |
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