From 1d60df49c1d601d166c3aa22ad460b4a9597280a Mon Sep 17 00:00:00 2001 From: krk Date: Thu, 15 Feb 2018 18:13:33 +0300 Subject: [PATCH] [rust] Header comment compacted, fix invalid JSON in header. --- src/Language/Rust.ts | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Language/Rust.ts b/src/Language/Rust.ts index ccb62ce1..8b02f196 100644 --- a/src/Language/Rust.ts +++ b/src/Language/Rust.ts @@ -20,6 +20,7 @@ import { UnionType, nullableFromUnion, Type, ClassType, matchType, removeNullFro import { Sourcelike, maybeAnnotated } from "../Source"; import { anyTypeIssueAnnotation, nullTypeIssueAnnotation } from "../Annotation"; import { EnumOption } from "../RendererOptions"; +import { defined } from "../Support"; enum Density { Normal, @@ -335,27 +336,20 @@ class RustRenderer extends ConvenienceRenderer { }; protected emitUsageExample(): void { + const topLevelName = defined(this.topLevels.keySeq().first()); this.emitMultiline( - `/* Example code that deserializes and serializes the model. -extern crate serde; - -#[macro_use] -extern crate serde_derive; - -extern crate serde_json; - -use generated_module::TopLevel; - -fn main() { - - let json = "{ answer: 42 }"; - - let top_level: TopLevel = serde_json::from_str(&json).unwrap(); - - let result = serde_json::to_string(&top_level).unwrap(); - - println!("{}", &result); -}*/` + `// Example code that deserializes and serializes the model. +// extern crate serde; +// #[macro_use] +// extern crate serde_derive; +// extern crate serde_json; +// +// use generated_module::${topLevelName}; +// +// fn main() { +// let json = r#"{"answer": 42}"#; +// let model: ${topLevelName} = serde_json::from_str(&json).unwrap(); +// }` ); }