https://github.com/wandercn/gostd_derive
proc_macro_derive library for gostd.
https://github.com/wandercn/gostd_derive
go-to-rust gostd gostd-derive proc-macro-derive rust-macro
Last synced: 3 months ago
JSON representation
proc_macro_derive library for gostd.
- Host: GitHub
- URL: https://github.com/wandercn/gostd_derive
- Owner: wandercn
- License: mit
- Created: 2021-09-27T14:30:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-28T11:37:12.000Z (over 4 years ago)
- Last Synced: 2026-02-07T17:25:26.009Z (4 months ago)
- Topics: go-to-rust, gostd, gostd-derive, proc-macro-derive, rust-macro
- Language: Rust
- Homepage: https://crates.io/crates/gostd_derive
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [gostd_derive](https://github.com/wandercn/gostd_derive)
[](https://crates.io/crates/gostd_derive)
[](https://docs.rs/gostd_derive)
[](./LICENSE)
[](https://crates.io/crates/gostd_derive)
[](#)
[](#)
[](#)
proc_macro_derive library for [gostd](https://github.com/wandercn/gostd).
## Fmt
用宏模拟实现Go中的Stringer接口。
在Go中printf函数,自动打印自定义实现的String方法返回内容。
- 使用方法
`#[derive(Fmt)]`
example:
```
use gostd_derive::Fmt;
#[derive(Fmt)]
struct Foo{
name:String,
}
// 必须为附加Fmt继承宏的Struct 或者 Emun 实现String方法才能正常运行
impl Foo {
fn String()->String{
"test".to_string()
}
}
```
- 功能逻辑
Fmt功能就是继承Display 并调用String()方法,在println!()实现自定义打印格式。
功能的rust表示如下。
```rust
impl fmt::Display for Foo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.String())
}
}
```
- 如何调试
本库只使用官方的proc_macro没有办法调试。
唯一方法,只有运行 `cargo check` 检查,不报错就没问题。