Skip to content

Commit 9df2c40

Browse files
committed
Use a cow for custom errors
1 parent bd40509 commit 9df2c40

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
borrow::Cow,
23
fmt::{Debug, Display},
34
fs, io,
45
};
@@ -16,7 +17,7 @@ pub type Result<T = (), E = Exit> = std::result::Result<T, E>;
1617
pub enum Exit {
1718
ArgError(sap::ParsingError),
1819
IoError(io::Error),
19-
Custom(&'static str),
20+
Custom(Cow<'static, str>),
2021
}
2122

2223
impl Debug for Exit {
@@ -47,6 +48,12 @@ impl From<io::Error> for Exit {
4748
}
4849
}
4950

51+
impl From<&'static str> for Exit {
52+
fn from(value: &'static str) -> Self {
53+
Self::Custom(Cow::Borrowed(value))
54+
}
55+
}
56+
5057
#[macro_export]
5158
macro_rules! version_text {
5259
($name:literal, $authors:literal) => {

0 commit comments

Comments
 (0)