- Notifications
You must be signed in to change notification settings - Fork352
Working Rust sdk#721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Working Rust sdk#721
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
dc88c34 Working Rust sdk
SilasMarvin866cc88 Clean up comments
SilasMarvina1a5bb1 Cleaned up clippy complaints in macro crate
SilasMarvin579385f Clean up file names
SilasMarvin82136f2 Added documentation
SilasMarvin41c2dee Documented the query_builder! macro
SilasMarvinbd3d479 Remove unnecessary Arc
SilasMarvin957a41a Merge branch 'master' into rust-pgml-sdk
SilasMarvinFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletionspgml-sdks/rust/pgml-macros/Cargo.lock
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
15 changes: 15 additions & 0 deletionspgml-sdks/rust/pgml-macros/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [package] | ||
| name = "pgml-macros" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
| [lib] | ||
| proc-macro = true | ||
| [dependencies] | ||
| syn = {version = "2.0.17", features=["full", "extra-traits", "fold", "visit"]} | ||
| quote = "1.0.9" | ||
| proc-macro2 = "1.0" | ||
| anyhow = "1.0.9" |
95 changes: 95 additions & 0 deletionspgml-sdks/rust/pgml-macros/src/common.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| use proc_macro2::Ident; | ||
| use quote::{format_ident, ToTokens}; | ||
| use syn::{ | ||
| parse::Parser, | ||
| punctuated::Punctuated, | ||
| visit::{self, Visit}, | ||
| ImplItemFn, ReturnType, Token, Visibility, | ||
| }; | ||
| use crate::types::{GetOutputType, GetSupportedType, OutputType, SupportedType}; | ||
| pub struct AttributeArgs { | ||
| pub args: Vec<String>, | ||
| } | ||
| impl AttributeArgs { | ||
| pub fn new(attributes: proc_macro::TokenStream) -> Self { | ||
| let attribute_parser = Punctuated::<Ident, Token![,]>::parse_terminated; | ||
| let parsed_attributes = attribute_parser | ||
| .parse(attributes) | ||
| .expect("Error parsing attributes for custom_methods macro"); | ||
| let args: Vec<String> = parsed_attributes | ||
| .into_pairs() | ||
| .map(|p| p.value().to_string()) | ||
| .collect(); | ||
| Self { args } | ||
| } | ||
| } | ||
| #[derive(Debug)] | ||
| pub struct GetImplMethod { | ||
| pub exists: bool, | ||
| pub method_ident: Ident, | ||
| pub is_async: bool, | ||
| pub method_arguments: Vec<(String, SupportedType)>, | ||
| pub receiver: Option<proc_macro2::TokenStream>, | ||
| pub output_type: OutputType, | ||
| } | ||
| impl Default for GetImplMethod { | ||
| fn default() -> Self { | ||
| GetImplMethod { | ||
| exists: false, | ||
| method_ident: format_ident!("nothing"), | ||
| is_async: false, | ||
| method_arguments: Vec::new(), | ||
| receiver: None, | ||
| output_type: OutputType::Default, | ||
| } | ||
| } | ||
| } | ||
| impl<'ast> Visit<'ast> for GetImplMethod { | ||
| fn visit_impl_item_fn(&mut self, i: &'ast ImplItemFn) { | ||
| if let Visibility::Public(_p) = i.vis { | ||
| self.exists = true; | ||
| visit::visit_impl_item_fn(self, i); | ||
| } | ||
| } | ||
| fn visit_signature(&mut self, i: &'ast syn::Signature) { | ||
| self.method_ident = i.ident.clone(); | ||
| self.is_async = i.asyncness.is_some(); | ||
| self.output_type = match &i.output { | ||
| ReturnType::Default => OutputType::Default, | ||
| ReturnType::Type(_ra, ty) => { | ||
| let mut get_output_type = GetOutputType::default(); | ||
| get_output_type.visit_type(ty); | ||
| get_output_type.output | ||
| } | ||
| }; | ||
| visit::visit_signature(self, i); | ||
| } | ||
| fn visit_receiver(&mut self, i: &'ast syn::Receiver) { | ||
| self.receiver = Some(i.to_token_stream()); | ||
| visit::visit_receiver(self, i); | ||
| } | ||
| fn visit_pat_type(&mut self, i: &'ast syn::PatType) { | ||
| let pat = i.pat.to_token_stream().to_string(); | ||
| let mut ty = GetSupportedType::default(); | ||
| ty.visit_type(&i.ty); | ||
| let ty = ty.ty.expect("No type found"); | ||
| self.method_arguments.push((pat, ty)); | ||
| visit::visit_pat_type(self, i); | ||
| } | ||
| fn visit_expr_return(&mut self, i: &'ast syn::ExprReturn) { | ||
| visit::visit_expr_return(self, i); | ||
| } | ||
| // We don't want to visit any of the statments in the methods | ||
| fn visit_block(&mut self, _i: &'ast syn::Block) {} | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.