[−][src]Function genco::prelude::quoted
pub fn quoted<T>(inner: T) -> QuotedFn<T>
Function to provide string quoting.
Note that quoting is applied automatically for literal strings inside of
the quote! macro, like: quote!("hello")
.
This is used to generated quoted strings, in the language of choice.
Examples
Example showcasing quoted strings when generating Rust.
use genco::prelude::*; let map = rust::import("std::collections", "HashMap"); let tokens = quote! { let mut m = #map::<u32, &str>::new(); m.insert(0, #(quoted("hello\" world"))); }; assert_eq!( vec![ "use std::collections::HashMap;", "", "let mut m = HashMap::<u32, &str>::new();", "m.insert(0, \"hello\\\" world\");", ], tokens.to_file_vec()?, );
Example: A quote inside a quote
Note that this requires extra buffering to occur when formatting the token stream.
use genco::prelude::*; let tokens: python::Tokens = quote!(#_(Hello #(quoted("World 😊")))); assert_eq!( "\"Hello \\\"World \\U0001f60a\\\"\"", tokens.to_string()?, );