5 releases

Uses old Rust 2015

0.2.2 Oct 3, 2017
0.2.1 Oct 3, 2017
0.2.0 Sep 23, 2017
0.1.1 Aug 13, 2017
0.1.0 Jun 25, 2017
Download history 12/week @ 2023-10-28 6/week @ 2023-11-04 4/week @ 2023-11-11 6/week @ 2023-11-18 23/week @ 2023-11-25 17/week @ 2023-12-02 4/week @ 2023-12-09 9/week @ 2023-12-16 14/week @ 2023-12-23 2/week @ 2023-12-30 5/week @ 2024-01-06 4/week @ 2024-01-13 12/week @ 2024-01-20 17/week @ 2024-01-27 10/week @ 2024-02-03 24/week @ 2024-02-10

64 downloads per month
Used in codeviz

MIT/Apache

25KB
832 lines

codeviz

Build Status crates.io

codeviz is a simple code generator for rust, specifically written for use in reproto.

This project is inspired by JavaPoet (https://github.com/square/javapoet)

Example

#[macro_use]
extern crate codeviz_macros;
extern crate codeviz_java;

use codeviz_java::*;

fn main() {
  let string_type = Type::class("java.lang", "String");
  let list_type = Type::class("java.util", "List");
  let json_creator_type = Type::class("com.fasterxml.jackson.annotation", "JsonCreator");
  let list_of_strings = list_type.with_arguments(vec![&string_type]);

  let values_field = FieldSpec::new(mods![Modifier::Private, Modifier::Final],
                                    &list_of_strings,
                                    "values");

  let values_argument =
      ArgumentSpec::new(mods![Modifier::Final], &list_of_strings, "values");

  let mut constructor = ConstructorSpec::new(mods![Modifier::Public]);
  constructor.push_annotation(AnnotationSpec::new(json_creator_type));
  constructor.push_argument(&values_argument);
  constructor.push(java_stmt!["this.values = ", values_argument]);

  let mut values_getter = MethodSpec::new(mods![Modifier::Public], "getValues");
  values_getter.returns(&list_of_strings);
  values_getter.push(java_stmt!["return this.", &values_field]);

  let mut class = ClassSpec::new(mods![Modifier::Public], "Test");
  class.push_field(&values_field);
  class.push_constructor(&constructor);
  class.push_method(&values_getter);

  let mut file = FileSpec::new("se.tedro");
  file.push_class(&class);

  let result = file.format();
}

Dependencies

~2.4–3.5MB
~69K SLoC