Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
@@ -0,0 +1 @@
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"bd124e22aae0503db8b645a58239d21ef972833a4e245546e57938b4c4144b56","Cargo.toml":"1a3b5a8d10fd0463945adab890305d19f6cba24486563dac486da07132154a3b","Cargo.toml.orig":"a720c10b019bc0671bba6e6394297e95ef95b460a62e1fc0a9d41ba1262799fe","src/lib.rs":"6151c4a9cf0d342b7d107fdc5624a8462c1a1ffdfc62e34d919ac2006af31f93"},"package":"debdc8729c37fdbf88472f97fd470393089f997a909e535ff67c544d18cfccf0"}
@@ -0,0 +1,6 @@
{
"git": {
"sha1": "3adebabf9e27cecedf200d82016b7d0dfec16c19"
},
"path_in_vcs": "sea-schema-derive"
}
+62
View File
@@ -0,0 +1,62 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "sea-schema-derive"
version = "0.3.0"
authors = ["Chris Tsang <tyt2y7@gmail.com>"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Derive macro for sea-schema's Name trait"
documentation = "https://docs.rs/sea-schema"
readme = false
keywords = [
"database",
"sql",
"mysql",
"postgres",
"sqlite",
]
categories = ["database"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/SeaQL/sea-schema"
resolver = "2"
[lib]
name = "sea_schema_derive"
path = "src/lib.rs"
proc-macro = true
[dependencies.heck]
version = "0.4"
default-features = false
[dependencies.proc-macro2]
version = "1"
default-features = false
[dependencies.quote]
version = "1"
default-features = false
[dependencies.syn]
version = "2"
features = [
"derive",
"parsing",
"proc-macro",
"printing",
]
default-features = false
+20
View File
@@ -0,0 +1,20 @@
[package]
name = "sea-schema-derive"
version = "0.3.0"
authors = [ "Chris Tsang <tyt2y7@gmail.com>" ]
edition = "2018"
description = "Derive macro for sea-schema's Name trait"
license = "MIT OR Apache-2.0"
documentation = "https://docs.rs/sea-schema"
repository = "https://github.com/SeaQL/sea-schema"
categories = [ "database" ]
keywords = [ "database", "sql", "mysql", "postgres", "sqlite" ]
[lib]
proc-macro = true
[dependencies]
syn = { version = "2", default-features = false, features = [ "derive", "parsing", "proc-macro", "printing" ] }
quote = { version = "1", default-features = false }
heck = { version = "0.4", default-features = false }
proc-macro2 = { version = "1", default-features = false }
+138
View File
@@ -0,0 +1,138 @@
use heck::ToSnakeCase;
use proc_macro::{self, TokenStream};
use proc_macro2::Span;
use quote::{quote, quote_spanned};
use syn::{
parse_macro_input, Attribute, DataEnum, DataStruct, DeriveInput, Expr, ExprLit, Fields, Ident,
Lit, Meta, Variant,
};
fn get_iden_attr(attrs: &[Attribute]) -> Option<&syn::Expr> {
for attr in attrs {
let name_value = match &attr.meta {
Meta::NameValue(nv) => nv,
_ => continue,
};
if name_value.path.is_ident("iden") || // interoperate with sea_query_derive Iden
name_value.path.is_ident("name")
{
return Some(&name_value.value);
}
}
None
}
fn get_catch_attr(attrs: &[Attribute]) -> Option<&syn::Expr> {
for attr in attrs {
let name_value = match &attr.meta {
Meta::NameValue(nv) => nv,
_ => continue,
};
if name_value.path.is_ident("catch") {
return Some(&name_value.value);
}
}
None
}
#[proc_macro_derive(Name, attributes(iden, name, catch))]
pub fn derive_iden(input: TokenStream) -> TokenStream {
let DeriveInput {
ident, data, attrs, ..
} = parse_macro_input!(input);
let table_name = match get_iden_attr(&attrs) {
Some(iden) => quote! { #iden },
None => {
let normalized = ident.to_string().to_snake_case();
quote! { #normalized }
}
};
let catch = match get_catch_attr(&attrs) {
Some(lit) => {
let name: String = match lit {
Expr::Lit(ExprLit {
lit: Lit::Str(name),
..
}) => name.value(),
_ => panic!("expected string for `catch`"),
};
let method = Ident::new(name.as_str(), Span::call_site());
quote! { #ident::#method(string) }
}
None => {
quote! { None }
}
};
// Currently we only support enums and unit structs
let variants =
match data {
syn::Data::Enum(DataEnum { variants, .. }) => variants,
syn::Data::Struct(DataStruct {
fields: Fields::Unit,
..
}) => {
return quote! {
impl sea_schema::Name for #ident {
fn from_str(string: &str) -> Option<Self> {
if string == #table_name {
Some(Self)
} else {
None
}
}
}
}
.into()
}
_ => return quote_spanned! {
ident.span() => compile_error!("you can only derive Name on enums or unit structs");
}
.into(),
};
if variants.is_empty() {
return TokenStream::new();
}
let variant = variants
.iter()
.filter(|v| get_catch_attr(&v.attrs).is_none() && matches!(v.fields, Fields::Unit))
.map(|Variant { ident, fields, .. }| match fields {
Fields::Unit => quote! { #ident },
_ => panic!(),
});
let name = variants.iter().map(|v| {
if let Some(iden) = get_iden_attr(&v.attrs) {
// If the user supplied a name, just use it
quote! { #iden }
} else if v.ident == "Table" {
table_name.clone()
} else {
let ident = v.ident.to_string().to_snake_case();
quote! { #ident }
}
});
let output = quote! {
impl sea_schema::Name for #ident {
fn from_str(string: &str) -> Option<Self> {
let result = match string {
#(#name => Some(Self::#variant),)*
_ => None,
};
if result.is_some() {
result
} else {
#catch
}
}
}
};
output.into()
}