pub struct Import { /* private fields */ }
Expand description
The import of a Python name from module import foo
.
Created through the import() function.
Implementations§
Source§impl Import
impl Import
Sourcepub fn with_alias<T>(self, alias: T) -> Self
pub fn with_alias<T>(self, alias: T) -> Self
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
pub fn with_module_alias<T>(self, module_alias: T) -> Self
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§
Source§impl<'a> FormatInto<Python> for &'a Import
impl<'a> FormatInto<Python> for &'a Import
Source§impl FormatInto<Python> for Import
impl FormatInto<Python> for Import
Source§impl Ord for Import
impl Ord for Import
Source§impl PartialOrd for Import
impl PartialOrd for Import
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