Implement Display for ConnectionUri
This commit makes it easy to display the configured database connection. Some
of the log messages ImportFromYamlAction need to display the configuration value.
@@ -21,7 +21,7 @@ pub mod postgres;
#[cfg(feature = "sqlite")]
pub mod sqlite;
-use std::str::FromStr;
+use std::{fmt::Display, str::FromStr};
#[cfg(all(feature = "sqlite", not(test)))]
use self::sqlite::ForeignKeyCustomizer;
@@ -159,6 +159,20 @@ pub enum ConnectionUri {
Sqlite(String),
}
+impl Display for ConnectionUri {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let string = match self {
+ #[cfg(feature = "memory")]
+ ConnectionUri::Memory => "memory",
+ #[cfg(feature = "sqlite")]
+ ConnectionUri::Sqlite(sqlite) => sqlite,
+ #[cfg(feature = "postgres")]
+ ConnectionUri::Postgres(pg) => pg,
+ };
+ write!(f, "{}", string)
+ }
+}
+
impl FromStr for ConnectionUri {
type Err = InvalidArgumentError;
