All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rust.model.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
{{>partial_header}}
{{#models}}
{{#model}}
{{#description}}
/// {{{classname}}} : {{{description}}}
{{/description}}

#[allow(unused_imports)]
use serde_json::Value;

#[derive(Debug, Serialize, Deserialize)]
pub struct {{classname}} {
{{#vars}}
  {{#description}}
  /// {{{description}}}
  {{/description}}
  #[serde(rename = "{{baseName}}")]
  {{name}}: {{^required}}Option<{{/required}}{{{datatype}}}{{^required}}>{{/required}}{{#hasMore}},{{/hasMore}}
{{/vars}}
}

impl {{classname}} {
  {{#description}}
  /// {{{description}}}
  {{/description}}
  pub fn new({{#requiredVars}}{{name}}: {{{datatype}}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{classname}} {
    {{classname}} {
      {{#vars}}
      {{name}}: {{#required}}{{name}}{{/required}}{{^required}}{{#isListContainer}}None{{/isListContainer}}{{#isMapContainer}}None{{/isMapContainer}}{{^isContainer}}None{{/isContainer}}{{/required}}{{#hasMore}},{{/hasMore}}
      {{/vars}}
    }
  }

  {{#vars}}
  pub fn set_{{name}}(&mut self, {{name}}: {{{datatype}}}) {
    self.{{name}} = {{^required}}Some({{name}}){{/required}}{{#required}}{{name}}{{/required}};
  }

  pub fn with_{{name}}(mut self, {{name}}: {{{datatype}}}) -> {{classname}} {
    self.{{name}} = {{^required}}Some({{name}}){{/required}}{{#required}}{{name}}{{/required}};
    self
  }

  pub fn {{name}}(&self) -> {{^required}}Option<{{/required}}&{{{datatype}}}{{^required}}>{{/required}} {
    {{#required}}&{{/required}}self.{{name}}{{^required}}.as_ref(){{/required}}
  }

  {{^required}}
  pub fn reset_{{name}}(&mut self) {
    self.{{name}} = None;
  }
  {{/required}}

  {{/vars}}
}

{{#isEnum}}
// TODO enum 
// List of {{{name}}}
//const (
//  {{#allowableValues}}
//  {{#enumVars}}
//  {{name}} {{{classname}}} = "{{{value}}}"
//  {{/enumVars}}
//  {{/allowableValues}}
//)
{{/isEnum}}


{{/model}}
{{/models}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy