2020-09-28 09:44:00 +00:00
|
|
|
use darling::ast::{Data, Fields};
|
|
|
|
use darling::util::Ignored;
|
|
|
|
use darling::{FromDeriveInput, FromField, FromMeta, FromVariant};
|
2020-10-14 09:08:57 +00:00
|
|
|
use inflector::Inflector;
|
2020-09-28 09:44:00 +00:00
|
|
|
use syn::{Attribute, Generics, Ident, Lit, LitStr, Meta, Type, Visibility};
|
2020-03-22 08:45:59 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta)]
|
|
|
|
#[darling(default)]
|
2020-03-22 08:45:59 +00:00
|
|
|
pub struct CacheControl {
|
2020-09-28 09:44:00 +00:00
|
|
|
public: bool,
|
|
|
|
private: bool,
|
2020-03-22 08:45:59 +00:00
|
|
|
pub max_age: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for CacheControl {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
public: true,
|
2020-09-28 09:44:00 +00:00
|
|
|
private: false,
|
2020-03-22 08:45:59 +00:00
|
|
|
max_age: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CacheControl {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub fn is_public(&self) -> bool {
|
|
|
|
!self.private && self.public
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum DefaultValue {
|
|
|
|
Default,
|
|
|
|
Value(Lit),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromMeta for DefaultValue {
|
|
|
|
fn from_word() -> darling::Result<Self> {
|
|
|
|
Ok(DefaultValue::Default)
|
|
|
|
}
|
2020-03-22 08:45:59 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
fn from_value(value: &Lit) -> darling::Result<Self> {
|
|
|
|
Ok(DefaultValue::Value(value.clone()))
|
2020-03-22 08:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromField)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct SimpleObjectField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
pub vis: Visibility,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub skip: bool,
|
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub deprecation: Option<String>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub owned: bool,
|
|
|
|
#[darling(default)]
|
2020-03-22 08:45:59 +00:00
|
|
|
pub cache_control: CacheControl,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub external: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub provides: Option<String>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub requires: Option<String>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub guard: Option<Meta>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct SimpleObject {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, SimpleObjectField>,
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
2020-10-20 03:49:31 +00:00
|
|
|
pub dummy: bool,
|
|
|
|
#[darling(default)]
|
2020-09-28 09:44:00 +00:00
|
|
|
pub name: Option<String>,
|
|
|
|
#[darling(default)]
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub rename_args: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
2020-09-28 09:44:00 +00:00
|
|
|
pub cache_control: CacheControl,
|
|
|
|
#[darling(default)]
|
|
|
|
pub extends: bool,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub struct Argument {
|
2020-03-05 06:23:55 +00:00
|
|
|
pub name: Option<String>,
|
2020-03-01 10:54:34 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
pub default_with: Option<LitStr>,
|
|
|
|
pub validator: Option<Meta>,
|
2020-06-19 04:37:52 +00:00
|
|
|
pub key: bool, // for entity
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct Object {
|
|
|
|
pub internal: bool,
|
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
pub rename_args: Option<RenameRule>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub cache_control: CacheControl,
|
|
|
|
pub extends: bool,
|
2020-03-05 06:23:55 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct ObjectField {
|
|
|
|
pub skip: bool,
|
|
|
|
pub entity: bool,
|
2020-03-05 06:23:55 +00:00
|
|
|
pub name: Option<String>,
|
|
|
|
pub deprecation: Option<String>,
|
2020-03-22 08:45:59 +00:00
|
|
|
pub cache_control: CacheControl,
|
2020-04-09 14:03:09 +00:00
|
|
|
pub external: bool,
|
|
|
|
pub provides: Option<String>,
|
|
|
|
pub requires: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub guard: Option<Meta>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub struct Enum {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<EnumItem, Ignored>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-02 00:24:49 +00:00
|
|
|
pub internal: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_items: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
2020-09-27 08:05:25 +00:00
|
|
|
pub remote: Option<String>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromVariant)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub struct EnumItem {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub fields: Fields<Ignored>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-03 03:48:00 +00:00
|
|
|
pub deprecation: Option<String>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct Union {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<UnionItem, Ignored>,
|
2020-05-10 04:41:05 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub name: Option<String>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromVariant)]
|
|
|
|
#[darling(attributes(graphql))]
|
2020-09-28 03:13:46 +00:00
|
|
|
pub struct UnionItem {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub fields: Fields<syn::Type>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-09-28 03:13:46 +00:00
|
|
|
pub flatten: bool,
|
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromField)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct InputObjectField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
pub vis: Visibility,
|
|
|
|
pub attrs: Vec<Attribute>,
|
2020-09-28 03:13:46 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-01 10:54:34 +00:00
|
|
|
pub name: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub default_with: Option<LitStr>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub validator: Option<Meta>,
|
|
|
|
#[darling(default)]
|
2020-09-03 12:00:33 +00:00
|
|
|
pub flatten: bool,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-03 03:48:00 +00:00
|
|
|
pub struct InputObject {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, InputObjectField>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-03 03:48:00 +00:00
|
|
|
pub internal: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-03 03:48:00 +00:00
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub rename_fields: Option<RenameRule>,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
2020-03-06 15:58:43 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub struct InterfaceFieldArgument {
|
|
|
|
pub name: String,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(rename = "type")]
|
|
|
|
pub ty: LitStr,
|
|
|
|
#[darling(default)]
|
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub default_with: Option<LitStr>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub struct InterfaceField {
|
|
|
|
pub name: String,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(rename = "type")]
|
|
|
|
pub ty: LitStr,
|
|
|
|
#[darling(default)]
|
2020-05-27 02:25:23 +00:00
|
|
|
pub method: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default, multiple, rename = "arg")]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub args: Vec<InterfaceFieldArgument>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub deprecation: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub external: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub provides: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub requires: Option<String>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromVariant)]
|
|
|
|
pub struct InterfaceMember {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub fields: Fields<syn::Type>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub struct Interface {
|
2020-09-28 09:44:00 +00:00
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<InterfaceMember, Ignored>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub internal: bool,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
#[darling(default)]
|
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub rename_args: Option<RenameRule>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default, multiple, rename = "field")]
|
2020-03-06 15:58:43 +00:00
|
|
|
pub fields: Vec<InterfaceField>,
|
2020-09-28 09:44:00 +00:00
|
|
|
#[darling(default)]
|
2020-04-09 14:03:09 +00:00
|
|
|
pub extends: bool,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct Scalar {
|
|
|
|
pub internal: bool,
|
|
|
|
pub name: Option<String>,
|
2020-03-06 15:58:43 +00:00
|
|
|
}
|
2020-04-17 03:06:33 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct Subscription {
|
2020-04-27 09:58:10 +00:00
|
|
|
pub internal: bool,
|
2020-05-19 05:27:01 +00:00
|
|
|
pub name: Option<String>,
|
2020-10-14 09:08:57 +00:00
|
|
|
pub rename_fields: Option<RenameRule>,
|
|
|
|
pub rename_args: Option<RenameRule>,
|
2020-09-28 09:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct SubscriptionFieldArgument {
|
|
|
|
pub name: Option<String>,
|
2020-05-19 05:27:01 +00:00
|
|
|
pub desc: Option<String>,
|
2020-09-28 09:44:00 +00:00
|
|
|
pub default: Option<DefaultValue>,
|
|
|
|
pub default_with: Option<LitStr>,
|
|
|
|
pub validator: Option<Meta>,
|
2020-04-27 09:58:10 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromMeta, Default)]
|
|
|
|
#[darling(default)]
|
|
|
|
pub struct SubscriptionField {
|
|
|
|
pub skip: bool,
|
|
|
|
pub name: Option<String>,
|
|
|
|
pub deprecation: Option<String>,
|
|
|
|
pub guard: Option<Meta>,
|
|
|
|
}
|
2020-04-27 09:58:10 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromField)]
|
|
|
|
pub struct MergedObjectField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
}
|
2020-05-01 23:57:34 +00:00
|
|
|
|
2020-09-28 09:44:00 +00:00
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct MergedObject {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, MergedObjectField>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub name: Option<String>,
|
|
|
|
#[darling(default)]
|
|
|
|
pub cache_control: CacheControl,
|
|
|
|
#[darling(default)]
|
|
|
|
pub extends: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromField)]
|
|
|
|
pub struct MergedSubscriptionField {
|
|
|
|
pub ident: Option<Ident>,
|
|
|
|
pub ty: Type,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(FromDeriveInput)]
|
|
|
|
#[darling(attributes(graphql), forward_attrs(doc))]
|
|
|
|
pub struct MergedSubscription {
|
|
|
|
pub ident: Ident,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
pub data: Data<Ignored, MergedSubscriptionField>,
|
|
|
|
|
|
|
|
#[darling(default)]
|
|
|
|
pub internal: bool,
|
|
|
|
#[darling(default)]
|
|
|
|
pub name: Option<String>,
|
2020-05-01 23:57:34 +00:00
|
|
|
}
|
2020-10-14 09:08:57 +00:00
|
|
|
|
2020-10-16 02:45:27 +00:00
|
|
|
#[derive(Debug, Copy, Clone, FromMeta)]
|
2020-10-14 09:08:57 +00:00
|
|
|
pub enum RenameRule {
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "lowercase")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Lower,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "UPPERCASE")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Upper,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "PascalCase")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Pascal,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "camelCase")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Camel,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "snake_case")]
|
2020-10-14 09:08:57 +00:00
|
|
|
Snake,
|
2020-10-16 02:45:27 +00:00
|
|
|
#[darling(rename = "SCREAMING_SNAKE_CASE")]
|
2020-10-14 09:08:57 +00:00
|
|
|
ScreamingSnake,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenameRule {
|
|
|
|
fn rename(&self, name: impl AsRef<str>) -> String {
|
|
|
|
match self {
|
|
|
|
Self::Lower => name.as_ref().to_lowercase(),
|
|
|
|
Self::Upper => name.as_ref().to_uppercase(),
|
|
|
|
Self::Pascal => name.as_ref().to_pascal_case(),
|
|
|
|
Self::Camel => name.as_ref().to_camel_case(),
|
|
|
|
Self::Snake => name.as_ref().to_snake_case(),
|
|
|
|
Self::ScreamingSnake => name.as_ref().to_screaming_snake_case(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub enum RenameTarget {
|
|
|
|
Type,
|
|
|
|
EnumItem,
|
|
|
|
Field,
|
|
|
|
Argument,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenameTarget {
|
|
|
|
fn rule(&self) -> RenameRule {
|
|
|
|
match self {
|
|
|
|
RenameTarget::Type => RenameRule::Pascal,
|
|
|
|
RenameTarget::EnumItem => RenameRule::ScreamingSnake,
|
|
|
|
RenameTarget::Field => RenameRule::Camel,
|
|
|
|
RenameTarget::Argument => RenameRule::Camel,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn rename(&self, name: impl AsRef<str>) -> String {
|
|
|
|
self.rule().rename(name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait RenameRuleExt {
|
|
|
|
fn rename(&self, name: impl AsRef<str>, target: RenameTarget) -> String;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RenameRuleExt for Option<RenameRule> {
|
|
|
|
fn rename(&self, name: impl AsRef<str>, target: RenameTarget) -> String {
|
|
|
|
self.unwrap_or(target.rule()).rename(name)
|
|
|
|
}
|
|
|
|
}
|