pub struct UnresolvedPackage {
    pub name: String,
    pub url: Option<String>,
    pub worlds: Arena<World>,
    pub interfaces: Arena<Interface>,
    pub types: Arena<TypeDef>,
    pub documents: Arena<Document>,
    pub foreign_deps: IndexMap<String, IndexMap<String, DocumentId>>,
    /* 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: String

Local name for this package.

§url: Option<String>

Optionally-specified URL for this package.

Must be specified for non-local dependencies. Note that this is never automatically set from UnresolvedPackage::parse methods, and it must be manually configured in the return value.

§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.

§documents: Arena<Document>

All documents found within this package.

Documents are sorted topologically in this arena with respect to imports between them.

§foreign_deps: IndexMap<String, IndexMap<String, DocumentId>>

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 a document name followed by the identifier within self.documents. The fields of self.documents describes the required types, interfaces, etc, that are required from each foreign 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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.