pub struct Import { /* private fields */ }
Expand description
The import of a JavaScript type import {foo} from "module.js"
.
Created through the import() function.
Implementations§
source§impl Import
impl Import
sourcepub fn with_alias<N>(self, alias: N) -> Selfwhere
N: Into<ItemStr>,
pub fn with_alias<N>(self, alias: N) -> Selfwhere N: Into<ItemStr>,
Change alias of imported item.
This implies that the import is a named import.
If this is set, you’ll get an import like:
import {<name> as <alias>} from <module>
Examples
use genco::prelude::*;
let a = js::import("collections", "vec");
let b = js::import("collections", "vec").with_alias("list");
let toks = quote! {
$a
$b
};
assert_eq!(
vec![
"import {vec, vec as list} from \"collections\";",
"",
"vec",
"list",
],
toks.to_file_vec()?
);
sourcepub fn into_default(self) -> Self
pub fn into_default(self) -> Self
Convert into a default import.
Examples
use genco::prelude::*;
let default_vec = js::import("collections", "defaultVec").into_default();
let toks = quote!($default_vec);
assert_eq!(
vec![
"import defaultVec from \"collections\";",
"",
"defaultVec",
],
toks.to_file_vec()?
);
sourcepub fn into_wildcard(self) -> Self
pub fn into_wildcard(self) -> Self
Convert into a wildcard import.
Examples
use genco::prelude::*;
let all = js::import("collections", "all").into_wildcard();
let toks = quote!($all);
assert_eq!(
vec![
"import * as all from \"collections\";",
"",
"all",
],
toks.to_file_vec()?
);
Trait Implementations§
source§impl<'a> FormatInto<JavaScript> for &'a Import
impl<'a> FormatInto<JavaScript> for &'a Import
source§fn format_into(self, tokens: &mut Tokens<JavaScript>)
fn format_into(self, tokens: &mut Tokens<JavaScript>)
Convert the type into tokens in-place. Read more
source§impl FormatInto<JavaScript> for Import
impl FormatInto<JavaScript> for Import
source§fn format_into(self, tokens: &mut Tokens<JavaScript>)
fn format_into(self, tokens: &mut Tokens<JavaScript>)
Convert the type into tokens in-place. Read more
source§impl LangItem<JavaScript> for Import
impl LangItem<JavaScript> for Import
source§impl Ord for Import
impl Ord for Import
source§impl PartialEq<Import> for Import
impl PartialEq<Import> for Import
source§impl PartialOrd<Import> for Import
impl PartialOrd<Import> for Import
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<'a> Register<JavaScript> for &'a Import
impl<'a> Register<JavaScript> for &'a Import
source§fn register(self, tokens: &mut Tokens<JavaScript>)
fn register(self, tokens: &mut Tokens<JavaScript>)
Convert the type into tokens.
source§impl Register<JavaScript> for Import
impl Register<JavaScript> for Import
source§fn register(self, tokens: &mut Tokens<JavaScript>)
fn register(self, tokens: &mut Tokens<JavaScript>)
Convert the type into tokens.