//! Generic interface to secret storage backends.

use std::error;

/// A generic error type which can contain any error caused by any of the
/// libraries we call.  This is used by our backend APIs for simplicity and
/// extensibility, and because we don't really care very much about why
/// things fail (at least not at this level).
pub type BoxedError = Box<error::Error+Send+Sync>;

/// Create a `BoxedError` with a simple string error.  We use this for
/// internal errors that we want to keep simple.
pub fn err<T: Into<String>>(message: T) -> BoxedError {
    From::from(message.into())
}

/// Create a `BoxedError` from a format string and format arguments.
macro_rules! err {
    ($( $e:expr ),*) =>
        ($crate::backend::err(format!($( $e ),*)));
}

/// Generic interface to a secret-storage backend.
pub trait Backend: Send + Sync {
    /// Get the value of the specified secret.
    fn var(&mut self, credential: &str) -> Result<String, BoxedError>;

    /// Get the value of the specified credential file.
    fn file(&mut self, path: &str) -> Result<String, BoxedError>;
}

//! Generic interface to secret storage backends.

use std::error;

/// A generic error type which can contain any error caused by any of the
/// libraries we call.  This is used by our backend APIs for simplicity and
/// extensibility, and because we don't really care very much about why
/// things fail (at least not at this level).
pub type BoxedError = Box<error::Error+Send+Sync>;

/// Create a `BoxedError` with a simple string error.  We use this for
/// internal errors that we want to keep simple.
pub fn err<T: Into<String>>(message: T) -> BoxedError {
    From::from(message.into())
}

/// Create a `BoxedError` from a format string and format arguments.
macro_rules! err {
    ($fmt:expr, $( $arg:expr ),*) =>
        ($crate::backend::err(format!($fmt, $( $arg ),*)));
}

/// Generic interface to a secret-storage backend.
pub trait Backend: Send + Sync {
    /// Get the value of the specified secret.
    fn var(&mut self, credential: &str) -> Result<String, BoxedError>;

    /// Get the value of the specified credential file.
    fn file(&mut self, path: &str) -> Result<String, BoxedError>;
}

--- 
+++ 
@@ -16,8 +16,8 @@
 
 /// Create a `BoxedError` from a format string and format arguments.
 macro_rules! err {
-    ($fmt:expr, $( $arg:expr ),*) =>
-        ($crate::backend::err(format!($fmt, $( $arg ),*)));
+    ($( $e:expr ),*) =>
+        ($crate::backend::err(format!($( $e ),*)));
 }
 
 /// Generic interface to a secret-storage backend.
Allow `err!` with no args except format string
