sway_core/language/parsed/use_statement.rs
1use crate::{language::Visibility, parsed::Span};
2use serde::{Deserialize, Serialize};
3use sway_types::ident::Ident;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub enum ImportType {
7 Star,
8 SelfImport(Span),
9 Item(Ident),
10}
11
12/// A [UseStatement] is a statement that imports something from a module into the local namespace.
13#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14pub struct UseStatement {
15 pub call_path: Vec<Ident>,
16 pub span: Span,
17 pub import_type: ImportType,
18 // If `is_relative_to_package_root` is true, then this use statement is a path relative to the
19 // project root. For example, if the path is `::X::Y` and occurs in package `P`, then the path
20 // refers to the full path `P::X::Y`.
21 // If `is_relative_to_package_root` is false, then there are two options:
22 // - The path refers to a path relative to the current namespace. For example, if the path is
23 // `X::Y` and it occurs in a module whose path is `P::M`, then the path refers to the full
24 // path `P::M::X::Y`.
25 // - The path refers to a path in an external package. For example, the path `X::Y` refers to an
26 // entity `Y` in the external package `X`.
27 pub is_relative_to_package_root: bool,
28 // If `reexport` is Visibility::Public, then this use statement reexports its imported binding.
29 // If not, then the import binding is private to the importing module.
30 pub reexport: Visibility,
31 pub alias: Option<Ident>,
32}