[][src]Function genco::lang::js::import

pub fn import<M, N>(module: M, name: N) -> Import where
    M: Into<Module>,
    N: Into<ItemStr>, 

Import an element from a module

Examples

use genco::prelude::*;

let default_vec = js::import("collections", "defaultVec").into_default();
let all = js::import("collections", "all").into_wildcard();
let vec = js::import("collections", "vec");
let vec_as_list = js::import("collections", "vec").with_alias("list");

let toks = quote! {
    #default_vec
    #all
    #vec
    #vec_as_list
};

assert_eq!(
    vec![
        "import * as all from \"collections\";",
        "import defaultVec, {vec, vec as list} from \"collections\";",
        "",
        "defaultVec",
        "all",
        "vec",
        "list",
    ],
    toks.to_file_vec()?
);