Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/wit-encoder/src/enum_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl EnumCase {
}
}

pub fn name(&mut self) -> &Ident {
pub fn name(&self) -> &Ident {
&self.name
}

Expand Down
19 changes: 12 additions & 7 deletions crates/wit-encoder/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ 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<Docs>,
}

impl Field {
pub fn new(name: impl Into<Ident>, 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
}

Expand All @@ -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<Type>) {
self.type_ = type_.into();
}
}

Expand Down
16 changes: 16 additions & 0 deletions crates/wit-encoder/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<impl Into<Docs>>) {
self.docs = docs.map(|d| d.into());
}
Expand Down
12 changes: 12 additions & 0 deletions crates/wit-encoder/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ impl Result_ {
err: None,
}
}
pub fn get_ok(&self) -> &Option<Type> {
&self.ok
}
pub fn get_ok_mut(&mut self) -> &mut Option<Type> {
&mut self.ok
}
pub fn err(type_: Type) -> Self {
Self {
ok: None,
err: Some(type_),
}
}
pub fn get_err(&self) -> &Option<Type> {
&self.err
}
pub fn get_err_mut(&mut self) -> &mut Option<Type> {
&mut self.err
}
pub fn both(ok: Type, err: Type) -> Self {
Self {
ok: Some(ok),
Expand Down
27 changes: 20 additions & 7 deletions crates/wit-encoder/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,33 +117,46 @@ impl Display for Type {
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub struct VariantCase {
name: Ident,
ty: Option<Type>,
#[cfg_attr(feature = "serde", serde(rename = "type"))]
type_: Option<Type>,
docs: Option<Docs>,
}

impl VariantCase {
pub fn empty(name: impl Into<Ident>) -> Self {
Self {
name: name.into(),
ty: None,
type_: None,
docs: None,
}
}

pub fn value(name: impl Into<Ident>, ty: Type) -> Self {
Self {
name: name.into(),
ty: Some(ty),
type_: Some(ty),
docs: None,
}
}

pub fn set_name(&mut self, name: impl Into<Ident>) {
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<Type> {
&mut self.ty
&mut self.type_
}

pub fn set_docs(&mut self, docs: Option<impl Into<Docs>>) {
Expand Down Expand Up @@ -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())?;
}
Expand Down Expand Up @@ -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_)?;
}
Expand Down