Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
SilasMarvin merged 8 commits intopostgresml:masterfromSilasMarvin:rust-pgml-sdk
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletionspgml-sdks/rust/pgml-macros/Cargo.lock
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

15 changes: 15 additions & 0 deletionspgml-sdks/rust/pgml-macros/Cargo.toml
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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) {}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp