blob: 379c3428104bfc6d36b7e2b2890d50c8c60dba0b (
plain)
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
|
use syn::parse::{Parse, ParseStream};
use syn::{braced, Ident, Token, TraitItem, TypePath, WhereClause};
pub struct MockInput
{
pub mock: Ident,
pub mocked_trait: TypePath,
pub items: Vec<TraitItem>,
}
impl Parse for MockInput
{
fn parse(input: ParseStream) -> Result<Self, syn::Error>
{
let mock = input.parse()?;
let _generics = input.parse::<Option<WhereClause>>()?;
let _braced_content;
let _brace = braced!(_braced_content in input);
input.parse::<Token![impl]>()?;
let mocked_trait = input.parse()?;
input.parse::<Token![for]>()?;
let impl_target = input.parse::<Ident>()?;
if impl_target != mock {
return Err(input.error("Expected this to be the mock"));
}
let content;
braced!(content in input);
let mut items = Vec::new();
while !content.is_empty() {
items.push(content.parse()?);
}
Ok(Self {
mock,
mocked_trait,
items,
})
}
}
|