Wiggle: tweaks to internal interfaces (#1469)

* [wiggle]: wiggle-generate internal interface for Names simplified

im using it in other libraries where I don't want to construct a
wiggle_generate::Config just to use the ctx_type out of it.

* wiggle: define_func can get trait name as argument

this flexibility needed for some customization over in lucet
This commit is contained in:
Pat Hickey
2020-04-06 07:51:17 -07:00
committed by GitHub
parent 45b3ed142c
commit c2cb4ea3ff
3 changed files with 17 additions and 10 deletions

View File

@@ -4,21 +4,19 @@ use quote::{format_ident, quote};
use witx::{AtomType, BuiltinType, Id, TypeRef};
use crate::lifetimes::LifetimeExt;
use crate::Config;
#[derive(Debug, Clone)]
pub struct Names {
config: Config,
ctx_type: Ident,
}
impl Names {
pub fn new(config: &Config) -> Names {
pub fn new(ctx_type: &Ident) -> Names {
Names {
config: config.clone(),
ctx_type: ctx_type.clone(),
}
}
pub fn ctx_type(&self) -> Ident {
self.config.ctx.name.clone()
self.ctx_type.clone()
}
pub fn type_(&self, id: &Id) -> TokenStream {
let ident = format_ident!("{}", id.as_str().to_camel_case());