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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! proc_macro_derive library for [gostd](https://github.com/wandercn/gostd).
use TokenStream;
use quote;
use syn;
/// Fmt implement the Stringer interface in Go using macro emulation.
/// Printf function in Go to automatically print the content returned by a custom implementation of String method.
/// <details class="rustdoc-toggle top-doc">
/// <summary class="docblock">zh-cn</summary>
/// 用宏模拟实现Go中的Stringer接口。
/// 在Go中printf函数,自动打印自定义实现的String方法返回内容。
/// </details>
///
/// - 使用方法
///
///`#[derive(Fmt)]`
///
/// # example:
///```no_run
///use gostd_derive::Fmt;
///
///#[derive(Fmt)]
///struct Foo{
/// name:String,
///}
/// // 必须为附加Fmt继承宏的Struct 或者 Emun 实现自定义的String方法才能正常运行
///
///impl Foo {
///
/// fn String(&self)->String{
/// "test".to_string()
/// }
///}
///```
///
///- 功能逻辑
///
/// Fmt功能就是继承Display 并调用自定义的String()方法,在println!()实现自定义打印格式。
///
/// 功能的rust表示如下。
///```no_run
///struct Foo{
/// name:String,
/// }
///
/// impl Foo {
///
/// fn String(&self)->String{
/// "test".to_string()
/// }
///}
/// // 下面的代码就是宏实现的批量生成代码的rust代码
///impl std::fmt::Display for Foo {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// write!(f, "{}", self.String())
/// }
///}
///```
///- 如何调试
///
/// 本库只使用官方的proc_macro没有办法调试。
/// 唯一方法,只有运行 `cargo check` 检查,没报错就问题。