pub struct Import { /* private fields */ }
Expand description
The import of a Python name from module import foo
.
Created through the import() function.
Implementations
sourceimpl Import
impl Import
sourcepub fn with_alias<T>(self, alias: T) -> Self where
T: Into<ItemStr>,
pub fn with_alias<T>(self, alias: T) -> Self where
T: Into<ItemStr>,
Configure the importe name with the specified alias.
This implised that the import is not qualified.
Examples
use genco::prelude::*;
let toks = quote! {
$(python::import("collections", "namedtuple").with_alias("nt"))
};
assert_eq!(
vec![
"from collections import namedtuple as nt",
"",
"nt",
],
toks.to_file_vec()?
);
sourcepub fn qualified(self) -> Self
pub fn qualified(self) -> Self
Indicate that the import is qualified (module prefixed).
Examples
use genco::prelude::*;
let toks = quote! {
$(python::import("collections", "namedtuple").qualified())
};
assert_eq!(
vec![
"import collections",
"",
"collections.namedtuple",
],
toks.to_file_vec()?
);
sourcepub fn with_module_alias<T>(self, module_alias: T) -> Self where
T: Into<ItemStr>,
pub fn with_module_alias<T>(self, module_alias: T) -> Self where
T: Into<ItemStr>,
Configure the imported name with the specified alias.
This implies that the import is qualified.
Examples
use genco::prelude::*;
let toks = quote! {
$(python::import("collections", "namedtuple").with_module_alias("c"))
};
assert_eq!(
vec![
"import collections as c",
"",
"c.namedtuple",
],
toks.to_file_vec()?
);
Trait Implementations
sourceimpl<'a> FormatInto<Python> for &'a Import
impl<'a> FormatInto<Python> for &'a Import
sourcefn format_into(self, tokens: &mut Tokens<Python>)
fn format_into(self, tokens: &mut Tokens<Python>)
Convert the type into tokens in-place. Read more
sourceimpl FormatInto<Python> for Import
impl FormatInto<Python> for Import
sourcefn format_into(self, tokens: &mut Tokens<Python>)
fn format_into(self, tokens: &mut Tokens<Python>)
Convert the type into tokens in-place. Read more
sourceimpl Ord for Import
impl Ord for Import
sourceimpl PartialOrd<Import> for Import
impl PartialOrd<Import> for Import
sourcefn partial_cmp(&self, other: &Import) -> Option<Ordering>
fn partial_cmp(&self, other: &Import) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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 more
impl Eq for Import
impl StructuralEq for Import
impl StructuralPartialEq for Import
Auto Trait Implementations
impl RefUnwindSafe for Import
impl Send for Import
impl Sync for Import
impl Unpin for Import
impl UnwindSafe for Import
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more