rust.model.mustache Maven / Gradle / Ivy
{{>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 - 2025 Weber Informatics LLC | Privacy Policy