You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If properties are not encoded natively in WIT, we'll probably end up with everybody choosing their own convention (based on their own language). Which is bound to end up looking foreign to the other languages.
Or we can prescribe a convention for tooling to convert from&to, but at that point we might as well just encode it into Wit itself.
My suggestion:
interfaceabc {
resourceblob {
content-type1: string { get } // Read-only propertycontent-type2: string { set } // Write-only property
content-type3: string { get, set } // Read/write property
content-type4: string // TODO: Without annotation defaults to { get } ? Or { get, set } ?
content-type5: string { // Customized signatures
get -> result<string, my-get-error>,
set -> result<_, my-set-error>,
}
content-type6: string { // Infallible getter, fallible setter
get, // If no custom signature is provided, the getter/setter is assumed to be infallible.
set -> result<_, my-set-error>,
}
/// General doc-comment applicable to both the getter & setter.
content-type7: string {
/// Documentation specific to the getter.
get,
/// Documentation specific to the setter.
set,
}
}
// Is equivalent to:
resource blob
%[get]blob.content-type1: func(self: borrow<blob>) -> string
%[set]blob.content-type2: func(self: borrow<blob>, value: string)
%[get]blob.content-type3: func(self: borrow<blob>) -> string
%[set]blob.content-type3: func(self: borrow<blob>, value: string)
// %[???]blob.content-type4
%[get]blob.content-type5: func(self: borrow<blob>) -> result<string, my-get-error>
%[set]blob.content-type5: func(self: borrow<blob>, value: string) -> result<_, my-set-error>
%[get]blob.content-type6: func(self: borrow<blob>) -> string
%[set]blob.content-type6: func(self: borrow<blob>, value: string) -> result<_, my-set-error>
}
Or more Javascript-esque:
interfaceabc {
resourceblob {
// Together these two declarations represent one logical property.content-type: get func() ->stringcontent-type: set func(value:string)
}
}
Most languages have either:
string MyProperty { get; set; }get myProperty()set myProperty(value)String getMyProperty()void setMyProperty(String value)my_property(&self) -> Stringset_my_property(&mut self, value: String) -> ()If properties are not encoded natively in WIT, we'll probably end up with everybody choosing their own convention (based on their own language). Which is bound to end up looking foreign to the other languages.
Or we can prescribe a convention for tooling to convert from&to, but at that point we might as well just encode it into Wit itself.
My suggestion:
Or more Javascript-esque:
Either way, in both variants getters and setters:
selfargument, regardless of the outcome of Allow consuming methods #226%[get]T.property-name: func(self: borrow<T>) -> T%[get]T.property-name: func(self: borrow<T>) -> result<T, error-type>%[set]T.property-name: func(self: borrow<T>, value: T)%[set]T.property-name: func(self: borrow<T>, value: T) -> result<_, error-type>