Skip to content

Commit cd34e60

Browse files
committed
Initial commit
0 parents  commit cd34e60

File tree

6 files changed

+1937
-0
lines changed

6 files changed

+1937
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "codegen"
3+
version = "0.1.0"
4+
authors = ["Carl Lerche <[email protected]>"]
5+
6+
[dependencies]
7+
ordermap = "0.3.0"

LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2017 Carl Lerche
2+
3+
Permission is hereby granted, free of charge, to any
4+
person obtaining a copy of this software and associated
5+
documentation files (the "Software"), to deal in the
6+
Software without restriction, including without
7+
limitation the rights to use, copy, modify, merge,
8+
publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software
10+
is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice
14+
shall be included in all copies or substantial portions
15+
of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Codegen
2+
3+
Provides an builder API to assist in generating Rust code.
4+
5+
## Installation
6+
7+
To use `codegen`, first add this to your `Cargo.toml`:
8+
9+
```toml
10+
[dependencies]
11+
codegen = { git = "https://github.com/carllerche/codegen" } # Soon on crates.io
12+
```
13+
14+
Next, add this to your crate:
15+
16+
```rust
17+
extern crate codegen;
18+
```
19+
20+
## Usage
21+
22+
1) Create a `Scope` instance.
23+
2) Use the builder API to add elements to the scope.
24+
3) Call `Scope::to_string()` to get the generated code.
25+
26+
For example:
27+
28+
```rust
29+
use codegen::Scope;
30+
31+
let mut scope = Scope::new();
32+
33+
scope.new_struct("Foo")
34+
.derive("Debug")
35+
.field("one", "usize")
36+
.field("two", "String");
37+
38+
println!("{}", scope.to_string());
39+
```
40+
41+
## Non-goals
42+
43+
`codegen` will not attempt to perform anything beyond basic formatting. For
44+
improved formatting, the generated code can be passed to `rustfmt`.

0 commit comments

Comments
 (0)