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>>,
    pub docs: Docs,
    /* 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.

§docs: Docs

Doc comments for this package.

Implementations§

source§

impl UnresolvedPackage

source

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.

source

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.

source

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.

source

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.

source

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

source§

fn clone(&self) -> UnresolvedPackage

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.