[][src]Function genco::tokens::quoted

pub fn quoted<T, L>(inner: T) -> impl FormatInto<L> where
    T: FormatInto<L>,
    L: Lang

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()?,
);