pub struct ImportLayout {
pub groups: Vec<ImportGroup>,
pub from_imports: Vec<ParsedFromImport>,
pub bare_imports: Vec<ParsedBareImport>,
pub source: ParseSource,
/* private fields */
}Expand description
Complete import layout for the top-level import section of a Python file.
Obtained via parse_import_layout.
Fields§
§groups: Vec<ImportGroup>Classified groups of contiguous import lines.
from_imports: Vec<ParsedFromImport>All module-level from X import … statements, in source order.
bare_imports: Vec<ParsedBareImport>All module-level import X statements, in source order.
Exposed as part of the public API for future consumers; currently the
providers use the existing_imports HashSet for deduplication and
only read from_imports for merge decisions.
source: ParseSourceHow this layout was produced — Ast or StringFallback.
Read in unit tests to assert which parser path was exercised; not
consumed by production code (the warn! in parse_import_layout
already records the fallback case in the log).
Implementations§
Source§impl ImportLayout
impl ImportLayout
Sourcepub fn line_strs(&self) -> Vec<&str>
pub fn line_strs(&self) -> Vec<&str>
Borrow all lines as &str slices (for passing to sort/insert helpers).
Sourcepub fn line(&self, idx: usize) -> &str
pub fn line(&self, idx: usize) -> &str
Get a single 0-based line as &str (empty string if out of bounds).
Sourcepub fn find_matching_from_import(
&self,
module: &str,
) -> Option<&ParsedFromImport>
pub fn find_matching_from_import( &self, module: &str, ) -> Option<&ParsedFromImport>
Find a module-level from <module> import … entry that is not a
star-import, regardless of whether it is single-line or multiline.
Returns None if no matching entry exists or only star-imports match.
Used by emit_kind_import_edits to decide whether to merge a new name
into an existing import line or insert a fresh line.
Auto Trait Implementations§
impl Freeze for ImportLayout
impl RefUnwindSafe for ImportLayout
impl Send for ImportLayout
impl Sync for ImportLayout
impl Unpin for ImportLayout
impl UnsafeUnpin for ImportLayout
impl UnwindSafe for ImportLayout
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more