diff --git a/crates/wit-encoder/src/enum_.rs b/crates/wit-encoder/src/enum_.rs index 6132ebb609..63757b470b 100644 --- a/crates/wit-encoder/src/enum_.rs +++ b/crates/wit-encoder/src/enum_.rs @@ -65,7 +65,7 @@ impl EnumCase { } } - pub fn name(&mut self) -> &Ident { + pub fn name(&self) -> &Ident { &self.name } diff --git a/crates/wit-encoder/src/record.rs b/crates/wit-encoder/src/record.rs index 6b2dca0a06..7bc505082b 100644 --- a/crates/wit-encoder/src/record.rs +++ b/crates/wit-encoder/src/record.rs @@ -28,7 +28,8 @@ impl Record { #[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub struct Field { pub(crate) name: Ident, - pub(crate) ty: Type, + #[cfg_attr(feature = "serde", serde(rename = "type"))] + pub(crate) type_: Type, pub(crate) docs: Option, } @@ -36,12 +37,12 @@ impl Field { pub fn new(name: impl Into, ty: Type) -> Self { Self { name: name.into(), - ty, + type_: ty, docs: None, } } - pub fn name(&mut self) -> &Ident { + pub fn name(&self) -> &Ident { &self.name } @@ -57,12 +58,16 @@ impl Field { &self.docs } - pub fn ty(&self) -> &Type { - &self.ty + pub fn type_(&self) -> &Type { + &self.type_ } - pub fn ty_mut(&mut self) -> &mut Type { - &mut self.ty + pub fn type_mut(&mut self) -> &mut Type { + &mut self.type_ + } + + pub fn set_type(&mut self, type_: impl Into) { + self.type_ = type_.into(); } } diff --git a/crates/wit-encoder/src/resource.rs b/crates/wit-encoder/src/resource.rs index e59e941760..cab2ff6a44 100644 --- a/crates/wit-encoder/src/resource.rs +++ b/crates/wit-encoder/src/resource.rs @@ -108,6 +108,22 @@ impl ResourceFunc { } } + pub fn results(&self) -> Option<&Results> { + match &self.kind { + ResourceFuncKind::Method(_, results) => Some(results), + ResourceFuncKind::Static(_, results) => Some(results), + ResourceFuncKind::Constructor => None, + } + } + + pub fn results_mut(&mut self) -> Option<&mut Results> { + match &mut self.kind { + ResourceFuncKind::Method(_, results) => Some(results), + ResourceFuncKind::Static(_, results) => Some(results), + ResourceFuncKind::Constructor => None, + } + } + pub fn set_docs(&mut self, docs: Option>) { self.docs = docs.map(|d| d.into()); } diff --git a/crates/wit-encoder/src/result.rs b/crates/wit-encoder/src/result.rs index ee8ff11909..e7436e3ad3 100644 --- a/crates/wit-encoder/src/result.rs +++ b/crates/wit-encoder/src/result.rs @@ -17,12 +17,24 @@ impl Result_ { err: None, } } + pub fn get_ok(&self) -> &Option { + &self.ok + } + pub fn get_ok_mut(&mut self) -> &mut Option { + &mut self.ok + } pub fn err(type_: Type) -> Self { Self { ok: None, err: Some(type_), } } + pub fn get_err(&self) -> &Option { + &self.err + } + pub fn get_err_mut(&mut self) -> &mut Option { + &mut self.err + } pub fn both(ok: Type, err: Type) -> Self { Self { ok: Some(ok), diff --git a/crates/wit-encoder/src/ty.rs b/crates/wit-encoder/src/ty.rs index 434868a536..62bf852f16 100644 --- a/crates/wit-encoder/src/ty.rs +++ b/crates/wit-encoder/src/ty.rs @@ -117,7 +117,8 @@ impl Display for Type { #[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub struct VariantCase { name: Ident, - ty: Option, + #[cfg_attr(feature = "serde", serde(rename = "type"))] + type_: Option, docs: Option, } @@ -125,7 +126,7 @@ impl VariantCase { pub fn empty(name: impl Into) -> Self { Self { name: name.into(), - ty: None, + type_: None, docs: None, } } @@ -133,17 +134,29 @@ impl VariantCase { pub fn value(name: impl Into, ty: Type) -> Self { Self { name: name.into(), - ty: Some(ty), + type_: Some(ty), docs: None, } } + pub fn set_name(&mut self, name: impl Into) { + self.name = name.into(); + } + + pub fn name(&self) -> &Ident { + &self.name + } + + pub fn name_mut(&mut self) -> &mut Ident { + &mut self.name + } + pub fn type_(&self) -> Option<&Type> { - self.ty.as_ref() + self.type_.as_ref() } pub fn type_mut(&mut self) -> &mut Option { - &mut self.ty + &mut self.type_ } pub fn set_docs(&mut self, docs: Option>) { @@ -348,7 +361,7 @@ impl Render for TypeDef { if let Some(docs) = &field.docs { docs.render(f, &opts)?; } - write!(f, "{}{}: {},\n", opts.spaces(), field.name, field.ty)?; + write!(f, "{}{}: {},\n", opts.spaces(), field.name, field.type_)?; } write!(f, "{}}}\n", opts.spaces())?; } @@ -408,7 +421,7 @@ impl Render for TypeDef { if let Some(docs) = &case.docs { docs.render(f, &opts)?; } - match &case.ty { + match &case.type_ { Some(type_) => { write!(f, "{}{}({}),\n", opts.spaces(), case.name, type_)?; }