[][src]Trait genco::ext::QuotedExt

pub trait QuotedExt {
    fn quoted(self) -> Quoted<Self>
    where
        Self: Into<ItemStr>
, { ... } }

Tokenizer for various types.

Provided methods

fn quoted(self) -> Quoted<Self> where
    Self: Into<ItemStr>, 

Trait to provide string quoting through <stmt>.quoted().

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::imported("std::collections", "HashMap");

let tokens = quote! {
    let mut m = #map::<u32, &str>::new();
    m.insert(0, #("hello\" world".quoted()));
};

assert_eq!(
    vec![
       "use std::collections::HashMap;",
       "",
       "let mut m = HashMap::<u32, &str>::new();",
       "m.insert(0, \"hello\\\" world\");",
    ],
    tokens.to_file_vec()?,
);
Loading content...

Implementors

impl<T> QuotedExt for T where
    T: Into<ItemStr>, 
[src]

Loading content...