Skip to content

Commit e4a7da8

Browse files
committed
feat: update example and little code cleaning
1 parent ddb1ae7 commit e4a7da8

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

examples/pi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use auto_rust::auto_implement;
22

33
#[auto_implement]
4-
/// This function calculates pi with a robust and very fast algorithm.
4+
/// This function calculates pi with a reliable algorithm.
55
fn calculate_pi_with_n_decimals(n: u32) -> f64 {
66
todo!()
77
}

src/generator.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::error::Error;
22

3-
use proc_macro::TokenStream;
4-
53
use crate::api::open_ai_chat_completions;
64

75
pub fn generate_body_function_from_head(head: String) -> Result<String, Box<dyn Error>> {
@@ -33,7 +31,7 @@ pub fn generate_body_function_from_head(head: String) -> Result<String, Box<dyn
3331
//TODO: improve the prompt to eliminate the need for this
3432
let body_str = body_str.trim_matches('`').to_string();
3533

36-
let implementation = format!("{} {{{}}}", head, body_str);
34+
let implementation = format!("{} {{\n{}\n}}", head, body_str);
3735

3836
Ok(implementation)
3937
}

src/lib.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
// extern crate proc_macro;
2-
31
mod api;
42
mod data;
53
mod generator;
64

75
use dotenv::dotenv;
86
use proc_macro::TokenStream;
9-
use syn::{parse, ItemFn, Lit, Meta, MetaNameValue, __private::ToTokens};
10-
use syn::{Attribute, LitStr};
7+
use syn::{ItemFn, __private::ToTokens};
118

129
use crate::generator::generate_body_function_from_head;
1310

@@ -25,9 +22,7 @@ pub fn implement(_item: TokenStream) -> TokenStream {
2522

2623
#[proc_macro_attribute]
2724
pub fn auto_implement(args: TokenStream, input: TokenStream) -> TokenStream {
28-
println!("{:?}", input);
29-
30-
let ast: ItemFn = syn::parse(input.clone()).expect("Failed to parse input as a function");
25+
let ast: ItemFn = syn::parse(input).expect("Failed to parse input as a function");
3126

3227
// Search for the information within the attributes.
3328

@@ -39,20 +34,9 @@ pub fn auto_implement(args: TokenStream, input: TokenStream) -> TokenStream {
3934

4035
for attr in ast.attrs {
4136
let data = attr.to_token_stream().to_string();
42-
// if attr.path().is_ident("doc") {
43-
// if let Ok(Meta::NameValue(meta_name_value)) = attr.parse_args() {
44-
// let info = meta_name_value.value.to_token_stream().to_string();
45-
// // if info.contains("This function calculates") {
46-
47-
// target_info = info;
48-
// break;
49-
// // }
50-
// }
51-
println!("{}", data);
5237

5338
prompt_input.push_str(&data);
5439
prompt_input.push('\n');
55-
// }
5640
}
5741

5842
prompt_input.push_str(&fn_header);

0 commit comments

Comments
 (0)