aboutsummaryrefslogtreecommitdiff
path: root/crates/proc_macro_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/proc_macro_api')
-rw-r--r--crates/proc_macro_api/src/lib.rs12
-rw-r--r--crates/proc_macro_api/src/process.rs20
2 files changed, 11 insertions, 21 deletions
diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs
index d5e87cf7d..0537286dd 100644
--- a/crates/proc_macro_api/src/lib.rs
+++ b/crates/proc_macro_api/src/lib.rs
@@ -42,9 +42,17 @@ impl tt::TokenExpander for ProcMacroProcessExpander {
42 fn expand( 42 fn expand(
43 &self, 43 &self,
44 subtree: &Subtree, 44 subtree: &Subtree,
45 _attr: Option<&Subtree>, 45 attr: Option<&Subtree>,
46 ) -> Result<Subtree, tt::ExpansionError> { 46 ) -> Result<Subtree, tt::ExpansionError> {
47 self.process.custom_derive(&self.dylib_path, subtree, &self.name) 47 let task = ExpansionTask {
48 macro_body: subtree.clone(),
49 macro_name: self.name.to_string(),
50 attributes: attr.cloned(),
51 lib: self.dylib_path.to_path_buf(),
52 };
53
54 let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?;
55 Ok(result.expansion)
48 } 56 }
49} 57}
50 58
diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs
index 301888a0e..d68723ada 100644
--- a/crates/proc_macro_api/src/process.rs
+++ b/crates/proc_macro_api/src/process.rs
@@ -10,11 +10,10 @@ use std::{
10}; 10};
11 11
12use crossbeam_channel::{bounded, Receiver, Sender}; 12use crossbeam_channel::{bounded, Receiver, Sender};
13use tt::Subtree;
14 13
15use crate::{ 14use crate::{
16 msg::{ErrorCode, Message, Request, Response, ResponseError}, 15 msg::{ErrorCode, Message, Request, Response, ResponseError},
17 rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}, 16 rpc::{ListMacrosResult, ListMacrosTask, ProcMacroKind},
18}; 17};
19 18
20#[derive(Debug, Default)] 19#[derive(Debug, Default)]
@@ -58,23 +57,6 @@ impl ProcMacroProcessSrv {
58 Ok(result.macros) 57 Ok(result.macros)
59 } 58 }
60 59
61 pub(crate) fn custom_derive(
62 &self,
63 dylib_path: &Path,
64 subtree: &Subtree,
65 derive_name: &str,
66 ) -> Result<Subtree, tt::ExpansionError> {
67 let task = ExpansionTask {
68 macro_body: subtree.clone(),
69 macro_name: derive_name.to_string(),
70 attributes: None,
71 lib: dylib_path.to_path_buf(),
72 };
73
74 let result: ExpansionResult = self.send_task(Request::ExpansionMacro(task))?;
75 Ok(result.expansion)
76 }
77
78 pub(crate) fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError> 60 pub(crate) fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError>
79 where 61 where
80 R: TryFrom<Response, Error = &'static str>, 62 R: TryFrom<Response, Error = &'static str>,