use std::fmt::{Debug, Display}; use std::str::FromStr; #[derive(Clone, Debug, PartialEq, Eq)] pub struct EmailAddress(email_address::EmailAddress); #[derive(Debug)] pub struct ParseError; impl Display for ParseError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, stringify!(ParseError)) } } impl std::error::Error for ParseError {} impl TryFrom for EmailAddress { type Error = ParseError; fn try_from(value: String) -> Result { Ok(EmailAddress( email_address::EmailAddress::from_str(&value).map_err(|_| ParseError)?, )) } } /// ParseErrorがトレイト境界を満たしているかチェック #[allow(non_camel_case_types)] struct __Assersion_EmailAddress_TryFrom where >::Error: std::error::Error; impl From for String { fn from(value: EmailAddress) -> Self { value.0.to_string() } } mod __sea_orm_newtype_email_address_mod { use super::*; impl From for sea_orm_newtype::Value { fn from(value: EmailAddress) -> Self { Into::::into(value).into() } } impl sea_orm_newtype::TryGetable for EmailAddress { fn try_get_by( res: &sea_orm_newtype::sea_orm::QueryResult, index: I, ) -> Result { Ok( TryInto::::try_into(res.try_get_by::(index)?) .map_err(|e| sea_orm_newtype::sea_orm::DbErr::Custom(e.to_string()))?, ) } } impl sea_orm_newtype::ValueType for EmailAddress { fn try_from( v: sea_orm_newtype::Value, ) -> Result { TryInto::::try_into(::try_from(v)?) .map_err(|_| sea_orm_newtype::sea_query::ValueTypeErr) } fn type_name() -> String { // ::type_name() stringify!(EmailAddress).to_owned() } fn array_type() -> sea_orm::sea_query::ArrayType { ::array_type() } fn column_type() -> sea_orm_newtype::sea_query::ColumnType { ::column_type() } } impl sea_orm_newtype::Nullable for EmailAddress { fn null() -> sea_orm_newtype::sea_query::Value { ::null() } } } use sea_orm::entity::prelude::*; #[derive(Clone, Debug, DeriveEntityModel)] #[sea_orm(table_name = "foo")] pub struct Model { #[sea_orm(primary_key)] id: uuid::Uuid, email_address: EmailAddress, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} fn main() {}