Struct wit_parser::UnresolvedPackage
source · pub struct UnresolvedPackage {
pub name: PackageName,
pub worlds: Arena<World>,
pub interfaces: Arena<Interface>,
pub types: Arena<TypeDef>,
pub foreign_deps: IndexMap<PackageName, IndexMap<String, AstItem>>,
/* private fields */
}
Expand description
Representation of a parsed WIT package which has not resolved external dependencies yet.
This representation has performed internal resolution of the WIT package itself, ensuring that all references internally are valid and the WIT was syntactically valid and such.
The fields of this structure represent a flat list of arrays unioned from
all documents within the WIT package. This means, for example, that all
types from all documents are located in self.types
. The fields of each
item can help splitting back out into packages/interfaces/etc as necessary.
Note that an UnresolvedPackage
cannot be queried in general about
information such as size or alignment as that would require resolution of
foreign dependencies. Translations such as to-binary additionally are not
supported on an UnresolvedPackage
due to the lack of knowledge about the
foreign types. This is intended to be an intermediate state which can be
inspected by embedders, if necessary, before quickly transforming to a
Resolve
to fully work with a WIT package.
After an UnresolvedPackage
is parsed it can be fully resolved with
Resolve::push
. During this operation a dependency map is specified which
will connect the foreign_deps
field of this structure to packages
previously inserted within the Resolve
. Embedders are responsible for
performing this resolution themselves.
Fields§
§name: PackageName
The namespace, name, and version information for this package.
worlds: Arena<World>
All worlds from all documents within this package.
Each world lists the document that it is from.
interfaces: Arena<Interface>
All interfaces from all documents within this package.
Each interface lists the document that it is from. Interfaces are listed in topological order as well so iteration through this arena will only reference prior elements already visited when working with recursive references.
types: Arena<TypeDef>
All types from all documents within this package.
Each type lists the interface or world that defined it, or nothing if it’s an anonymous type. Types are listed in this arena in topological order to ensure that iteration through this arena will only reference other types transitively that are already iterated over.
foreign_deps: IndexMap<PackageName, IndexMap<String, AstItem>>
All foreign dependencies that this package depends on.
These foreign dependencies must be resolved to convert this unresolved
package into a Resolve
. The map here is keyed by the name of the
foreign package that this depends on, and the sub-map is keyed by an
interface name followed by the identifier within self.interfaces
. The
fields of self.interfaces
describes the required types that are from
each foreign interface.
Implementations§
source§impl UnresolvedPackage
impl UnresolvedPackage
sourcepub fn parse(path: &Path, contents: &str) -> Result<Self>
pub fn parse(path: &Path, contents: &str) -> Result<Self>
Parses the given string as a wit document.
The path
argument is used for error reporting. The contents
provided
will not be able to use pkg
use paths to other documents.
sourcepub fn parse_path(path: &Path) -> Result<Self>
pub fn parse_path(path: &Path) -> Result<Self>
Parse a WIT package at the provided path.
The path provided is inferred whether it’s a file or a directory. A file
is parsed with UnresolvedPackage::parse_file
and a directory is
parsed with UnresolvedPackage::parse_dir
.
sourcepub fn parse_file(path: &Path) -> Result<Self>
pub fn parse_file(path: &Path) -> Result<Self>
Parses a WIT package from the file provided.
The WIT package returned will be a single-document package and will not
be able to use pkg
paths to other documents.
sourcepub fn parse_dir(path: &Path) -> Result<Self>
pub fn parse_dir(path: &Path) -> Result<Self>
Parses a WIT package from the directory provided.
All files with the extension *.wit
or *.wit.md
will be loaded from
path
into the returned package.
sourcepub fn source_files(&self) -> impl Iterator<Item = &Path>
pub fn source_files(&self) -> impl Iterator<Item = &Path>
Returns an iterator over the list of source files that were read when parsing this package.
Trait Implementations§
source§impl Clone for UnresolvedPackage
impl Clone for UnresolvedPackage
source§fn clone(&self) -> UnresolvedPackage
fn clone(&self) -> UnresolvedPackage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more