Implements fmt::Display for ActiveEnum (#986)

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
This commit is contained in:
Billy Chan 2022-10-23 22:29:31 +08:00 committed by GitHub
parent dd92a6860b
commit b91ca2b778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -353,6 +353,14 @@ impl ActiveEnum {
<<Self as sea_orm::ActiveEnum>::Value as sea_orm::sea_query::Nullable>::null() <<Self as sea_orm::ActiveEnum>::Value as sea_orm::sea_query::Nullable>::null()
} }
} }
#[automatically_derived]
impl std::fmt::Display for #ident {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let v: sea_orm::sea_query::Value = self.to_value().into();
write!(f, "{}", v)
}
}
) )
} }
} }

View File

@ -241,6 +241,9 @@ mod tests {
DeriveCategory::name().to_string() DeriveCategory::name().to_string()
); );
assert_eq!(Category::values(), DeriveCategory::values()); assert_eq!(Category::values(), DeriveCategory::values());
assert_eq!(format!("{}", DeriveCategory::Big), "'B'");
assert_eq!(format!("{}", DeriveCategory::Small), "'S'");
} }
#[test] #[test]
@ -295,6 +298,10 @@ mod tests {
); );
assert_eq!($ident::db_type(), ColumnType::$col_def.def()); assert_eq!($ident::db_type(), ColumnType::$col_def.def());
assert_eq!(format!("{}", $ident::Big), "1");
assert_eq!(format!("{}", $ident::Small), "0");
assert_eq!(format!("{}", $ident::Negative), "-10");
}; };
} }
@ -356,6 +363,9 @@ mod tests {
); );
assert_eq!($ident::db_type(), ColumnType::$col_def.def()); assert_eq!($ident::db_type(), ColumnType::$col_def.def());
assert_eq!(format!("{}", $ident::Big), "1");
assert_eq!(format!("{}", $ident::Small), "0");
}; };
} }