Add #[automatically_derived] to all derived implementations

This commit is contained in:
Billy Chan 2021-10-15 12:59:56 +08:00 committed by Chris Tsang
parent 2a34381a8d
commit 864ec522b8
10 changed files with 24 additions and 0 deletions

View File

@ -68,12 +68,14 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result<Token
#(pub #field: sea_orm::ActiveValue<#ty>),*
}
#[automatically_derived]
impl std::default::Default for ActiveModel {
fn default() -> Self {
<Self as sea_orm::ActiveModelBehavior>::new()
}
}
#[automatically_derived]
impl std::convert::From<<Entity as EntityTrait>::Model> for ActiveModel {
fn from(m: <Entity as EntityTrait>::Model) -> Self {
Self {
@ -82,12 +84,14 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result<Token
}
}
#[automatically_derived]
impl sea_orm::IntoActiveModel<ActiveModel> for <Entity as EntityTrait>::Model {
fn into_active_model(self) -> ActiveModel {
self.into()
}
}
#[automatically_derived]
impl sea_orm::ActiveModelTrait for ActiveModel {
type Entity = Entity;

View File

@ -4,6 +4,7 @@ use syn::Data;
pub fn expand_derive_active_model_behavior(_ident: Ident, _data: Data) -> syn::Result<TokenStream> {
Ok(quote!(
#[automatically_derived]
impl sea_orm::ActiveModelBehavior for ActiveModel {}
))
}

View File

@ -54,6 +54,7 @@ pub fn impl_default_as_str(ident: &Ident, data: &Data) -> syn::Result<TokenStrea
.collect();
Ok(quote!(
#[automatically_derived]
impl #ident {
fn default_as_str(&self) -> &str {
match self {
@ -84,6 +85,7 @@ pub fn impl_col_from_str(ident: &Ident, data: &Data) -> syn::Result<TokenStream>
});
Ok(quote!(
#[automatically_derived]
impl std::str::FromStr for #ident {
type Err = sea_orm::ColumnFromStrErr;
@ -103,6 +105,7 @@ pub fn expand_derive_column(ident: &Ident, data: &Data) -> syn::Result<TokenStre
Ok(quote!(
#impl_iden
#[automatically_derived]
impl sea_orm::IdenStatic for #ident {
fn as_str(&self) -> &str {
self.default_as_str()
@ -120,6 +123,7 @@ pub fn expand_derive_custom_column(ident: &Ident, data: &Data) -> syn::Result<To
#impl_col_from_str
#[automatically_derived]
impl sea_orm::Iden for #ident {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "{}", self.as_str()).unwrap();

View File

@ -70,6 +70,7 @@ impl DeriveEntity {
.unwrap_or_else(|| quote!(None));
quote!(
#[automatically_derived]
impl sea_orm::entity::EntityName for #ident {
fn schema_name(&self) -> Option<&str> {
#expanded_schema_name
@ -93,6 +94,7 @@ impl DeriveEntity {
} = self;
quote!(
#[automatically_derived]
impl sea_orm::entity::EntityTrait for #ident {
type Model = #model_ident;
@ -109,6 +111,7 @@ impl DeriveEntity {
let ident = &self.ident;
quote!(
#[automatically_derived]
impl sea_orm::Iden for #ident {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "{}", self.as_str()).unwrap();
@ -121,6 +124,7 @@ impl DeriveEntity {
let ident = &self.ident;
quote!(
#[automatically_derived]
impl sea_orm::IdenStatic for #ident {
fn as_str(&self) -> &str {
<Self as sea_orm::EntityName>::table_name(self)

View File

@ -37,6 +37,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
#[derive(Copy, Clone, Default, Debug, sea_orm::prelude::DeriveEntity)]
pub struct Entity;
#[automatically_derived]
impl sea_orm::prelude::EntityName for Entity {
fn schema_name(&self) -> Option<&str> {
#schema_name
@ -273,6 +274,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
#primary_keys
}
#[automatically_derived]
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = #primary_key_types;
@ -290,6 +292,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
#columns_enum
}
#[automatically_derived]
impl sea_orm::prelude::ColumnTrait for Column {
type EntityName = Entity;

View File

@ -29,6 +29,7 @@ pub fn expand_derive_from_query_result(ident: Ident, data: Data) -> syn::Result<
.collect();
Ok(quote!(
#[automatically_derived]
impl sea_orm::FromQueryResult for #ident {
fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::DbErr> {
Ok(Self {

View File

@ -76,6 +76,7 @@ impl IntoActiveModel {
});
quote!(
#[automatically_derived]
impl sea_orm::IntoActiveModel<#active_model_ident> for #ident {
fn into_active_model(self) -> #active_model_ident {
#active_model_ident {

View File

@ -123,6 +123,7 @@ impl DeriveModel {
.collect();
quote!(
#[automatically_derived]
impl sea_orm::FromQueryResult for #ident {
fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::DbErr> {
Ok(Self {
@ -160,6 +161,7 @@ impl DeriveModel {
let missing_field_msg = format!("field does not exist on {}", ident);
quote!(
#[automatically_derived]
impl sea_orm::ModelTrait for #ident {
type Entity = #entity_ident;

View File

@ -31,12 +31,14 @@ pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenS
.collect();
Ok(quote!(
#[automatically_derived]
impl sea_orm::Iden for #ident {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "{}", self.as_str()).unwrap();
}
}
#[automatically_derived]
impl sea_orm::IdenStatic for #ident {
fn as_str(&self) -> &str {
match self {
@ -45,6 +47,7 @@ pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenS
}
}
#[automatically_derived]
impl sea_orm::PrimaryKeyToColumn for #ident {
type Column = Column;

View File

@ -143,6 +143,7 @@ impl DeriveRelation {
.collect::<Result<Vec<_>, _>>()?;
Ok(quote!(
#[automatically_derived]
impl sea_orm::entity::RelationTrait for #ident {
fn def(&self) -> sea_orm::entity::RelationDef {
match self {