add a lifetime to the wiggle_runtime::GuestErrorType trait (#41)

* add a lifetime to the wiggle_runtime::GuestErrorType trait, wiggle_tests::WasiCtx struct

* wiggle-generate: make config parsing public so it can be reused in lucet
This commit is contained in:
Pat Hickey
2020-03-10 14:48:57 -07:00
committed by GitHub
parent 2139020d6d
commit cd484e4993
14 changed files with 46 additions and 34 deletions

View File

@@ -14,25 +14,32 @@ pub struct Config {
pub ctx: CtxConf,
}
enum ConfigField {
#[derive(Debug, Clone)]
pub enum ConfigField {
Witx(WitxConf),
Ctx(CtxConf),
}
impl ConfigField {
pub fn parse_pair(ident: &str, value: ParseStream, err_loc: Span) -> Result<Self> {
match ident {
"witx" => Ok(ConfigField::Witx(value.parse()?)),
"ctx" => Ok(ConfigField::Ctx(value.parse()?)),
_ => Err(Error::new(err_loc, "expected `witx` or `ctx`")),
}
}
}
impl Parse for ConfigField {
fn parse(input: ParseStream) -> Result<Self> {
let id: Ident = input.parse()?;
let _colon: Token![:] = input.parse()?;
match id.to_string().as_ref() {
"witx" => Ok(ConfigField::Witx(input.parse()?)),
"ctx" => Ok(ConfigField::Ctx(input.parse()?)),
_ => Err(Error::new(id.span(), "expected `witx` or `ctx`")),
}
Self::parse_pair(id.to_string().as_ref(), input, id.span())
}
}
impl Config {
fn build(fields: impl Iterator<Item = ConfigField>, err_loc: Span) -> Result<Self> {
pub fn build(fields: impl Iterator<Item = ConfigField>, err_loc: Span) -> Result<Self> {
let mut witx = None;
let mut ctx = None;
for f in fields {

View File

@@ -1,4 +1,4 @@
mod config;
pub mod config;
mod funcs;
mod lifetimes;
mod module_trait;