refactor(StringError): Take more comfortable types in StringError::new

Follow up to #77.
This commit is contained in:
Lewin Bormann
2019-06-14 10:44:44 +02:00
parent 10f94a3fd4
commit d631c259e8
3 changed files with 6 additions and 6 deletions

View File

@@ -255,7 +255,7 @@ where
Err(err) => err.to_string(),
};
return Err(Box::new(StringError::new(
storage_err + err_str,
&(storage_err + err_str),
err_description.as_ref(),
)));
}

View File

@@ -306,8 +306,8 @@ where
|| token.expires_in.is_none()
{
Err(Box::new(StringError::new(
"Token response lacks fields".to_string(),
Some(&format!("{:?}", token)),
"Token response lacks fields",
Some(format!("{:?}", token).as_str()),
)))
} else {
Ok(token.to_oauth_token())

View File

@@ -88,11 +88,11 @@ impl fmt::Display for StringError {
}
impl StringError {
pub fn new(error: String, desc: Option<&String>) -> StringError {
let mut error = error;
pub fn new<S: AsRef<str>>(error: S, desc: Option<S>) -> StringError {
let mut error = error.as_ref().to_string();
if let Some(d) = desc {
error.push_str(": ");
error.push_str(&*d);
error.push_str(d.as_ref());
}
StringError { error: error }