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) -> Self
pub fn with_alias<N>(self, alias: N) -> Self
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 PartialOrd for Import
impl PartialOrd for Import
Source§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.
impl Eq for Import
impl StructuralPartialEq for Import
Auto Trait Implementations§
impl Freeze for Import
impl RefUnwindSafe for Import
impl Send for Import
impl Sync for Import
impl Unpin for Import
impl UnwindSafe for Import
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more