1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Integration tests for generic method support in #[reflect_methods] proc macro.
use elicitation::elicit_newtype;
use elicitation_derive::reflect_methods;
// Create newtype wrapper
elicit_newtype!(Vec<String>, as StringList);
// Simplified test with just one generic method
#[reflect_methods]
impl StringList {
pub fn contains<T>(&self, item: &T) -> bool
where
T: elicitation::Elicitation
+ schemars::JsonSchema
+ PartialEq<String>
+ elicitation::ElicitComplete,
{
self.0.iter().any(|s| item == s)
}
}
#[test]
fn test_generic_method_compiles() {
// Just verify that the code compiles
// The #[reflect_methods] macro should have generated:
// 1. ContainsParams<T> struct
// 2. contains_tool<T>(...) method
}
#[test]
fn test_generic_method_delegation() {
let list = StringList::from(vec!["hello".to_string(), "world".to_string()]);
// Test contains - delegates to inner Vec
assert!(list.contains(&"hello".to_string()));
assert!(!list.contains(&"goodbye".to_string()));
}
// The generated code should look like:
//
// #[derive(Debug, Clone, Elicit, JsonSchema)]
// pub struct ContainsParams<T>
// where
// T: Elicitation + JsonSchema + PartialEq<String>,
// {
// pub item: T,
// }
//
// impl StringList {
// #[tool(description = "contains operation")]
// pub fn contains_tool<T>(
// &self,
// params: Parameters<ContainsParams<T>>,
// ) -> Result<Json<bool>, ErrorData>
// where
// T: Elicitation + JsonSchema + PartialEq<String>,
// {
// let item = ¶ms.0.item;
// self.contains::<T>(item)
// .map(Json)
// .map_err(|e| ErrorData::internal_error(e.to_string(), None))
// }
// }