https://github.com/sunng87/tojson_macros
Simple rust syntax extension generates default ToJson implementation
https://github.com/sunng87/tojson_macros
Last synced: 3 months ago
JSON representation
Simple rust syntax extension generates default ToJson implementation
- Host: GitHub
- URL: https://github.com/sunng87/tojson_macros
- Owner: sunng87
- License: apache-2.0
- Created: 2015-04-19T11:22:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-21T13:50:11.000Z (almost 9 years ago)
- Last Synced: 2025-09-25T11:27:43.530Z (4 months ago)
- Language: Rust
- Size: 34.2 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# tojson_macros
This is a Rust syntax extension generates default `::rustc_serialize::json::ToJson`
implementation for you. This library now uses macros 1.1 for code
generation. However it still requires rust nightly to build on.
[](https://crates.io/crates/tojson_macros)
[](https://travis-ci.org/sunng87/tojson_macros)
## Crate
```toml
tojson_macros = "^0.3"
```
## Example
Simply add `#[derive(ToJson)]` to your struct. Currently only Struct
is supported.
```rust
#![feature(proc_macro)]
#[macro_use]
extern crate tojson_macros;
extern crate rustc_serialize;
use rustc_serialize::json::ToJson;
#[derive(ToJson)]
struct Person {
name: String,
age: u8
}
let p = Person { name: "Ning".to_string(), age: 28u8 };
println!("{}", p.to_json());
```
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the
Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.