/// An `import` statement and entry in a WebAssembly component. #[derive(Debug)] pubstruct ComponentImport<'a> { /// Where this `import` was defined pub span: Span, /// The name of the item being imported. pub name: ComponentExternName<'a>, /// The item that's being imported. pub item: ItemSig<'a>,
}
impl<'a> Parse<'a> for ComponentImport<'a> { fn parse(parser: Parser<'a>) -> Result<Self> { let span = parser.parse::<kw::import>()?.0; let name = parser.parse()?; let item = parser.parens(|p| p.parse())?;
Ok(ComponentImport { span, name, item })
}
}
/// The different ways an import can be named. #[derive(Debug, Copy, Clone)] pubstruct ComponentExternName<'a>(pub &'a str);
impl<'a> Parse<'a> for ComponentExternName<'a> { fn parse(parser: Parser<'a>) -> Result<Self> { // Prior to WebAssembly/component-model#263 the syntactic form // `(interface "...")` was supported for interface names. This is no // longer part of the syntax of the binary format nor the text format, // but continue to parse this as "sugar" for the current format. This // is intended to avoid breaking folks and provide a smoother transition // forward. let name = if parser.peek::<LParen>()? {
parser.parens(|p| {
p.parse::<kw::interface>()?;
p.parse()
})?
} else {
parser.parse()?
};
Ok(ComponentExternName(name))
}
}
/// An item signature for imported items. #[derive(Debug)] pubstruct ItemSig<'a> { /// Where this item is defined in the source. pub span: Span, /// An optional identifier used during name resolution to refer to this item /// from the rest of the component. pub id: Option<Id<'a>>, /// An optional name which, for functions, will be stored in the /// custom `name` section. pub name: Option<NameAnnotation<'a>>, /// What kind of item this is. pub kind: ItemSigKind<'a>,
}
fn parse_item_sig<'a>(parser: Parser<'a>, name: bool) -> Result<ItemSig<'a>> { letmut l = parser.lookahead1(); let (span, parse_kind): (_, fn(Parser<'a>) -> Result<ItemSigKind<'a>>) = if l.peek::<kw::core>()? { let span = parser.parse::<kw::core>()?.0;
parser.parse::<kw::module>()?;
(span, |parser| Ok(ItemSigKind::CoreModule(parser.parse()?)))
} elseif l.peek::<kw::func>()? { let span = parser.parse::<kw::func>()?.0;
(span, |parser| Ok(ItemSigKind::Func(parser.parse()?)))
} elseif l.peek::<kw::component>()? { let span = parser.parse::<kw::component>()?.0;
(span, |parser| Ok(ItemSigKind::Component(parser.parse()?)))
} elseif l.peek::<kw::instance>()? { let span = parser.parse::<kw::instance>()?.0;
(span, |parser| Ok(ItemSigKind::Instance(parser.parse()?)))
} elseif l.peek::<kw::value>()? { let span = parser.parse::<kw::value>()?.0;
(span, |parser| Ok(ItemSigKind::Value(parser.parse()?)))
} elseif l.peek::<kw::r#type>()? { let span = parser.parse::<kw::r#type>()?.0;
(span, |parser| {
Ok(ItemSigKind::Type(parser.parens(|parser| parser.parse())?))
})
} else { return Err(l.error());
};
Ok(ItemSig {
span,
id: if name { parser.parse()? } else { None },
name: if name { parser.parse()? } else { None },
kind: parse_kind(parser)?,
})
}
/// The kind of signatures for imported items. #[derive(Debug)] pubenum ItemSigKind<'a> { /// The item signature is for a core module.
CoreModule(CoreTypeUse<'a, ModuleType<'a>>), /// The item signature is for a function.
Func(ComponentTypeUse<'a, ComponentFunctionType<'a>>), /// The item signature is for a component.
Component(ComponentTypeUse<'a, ComponentType<'a>>), /// The item signature is for an instance.
Instance(ComponentTypeUse<'a, InstanceType<'a>>), /// The item signature is for a value.
Value(ComponentValTypeUse<'a>), /// The item signature is for a type. Type(TypeBounds<'a>),
}
/// Represents the bounds applied to types being imported. #[derive(Debug)] pubenum TypeBounds<'a> { /// The equality type bounds.
Eq(Index<'a>), /// A resource type is imported/exported,
SubResource,
}
/// A listing of a inline `(import "foo")` statement. /// /// This is the same as `core::InlineImport` except only one string import is /// required. #[derive(Debug, Clone)] pubstruct InlineImport<'a> { /// The name of the item being imported. pub name: ComponentExternName<'a>,
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.