Skip to content

Commit 10346b5

Browse files
committed
Add introductory text about own/borrow handles in resource section
1 parent e718f98 commit 10346b5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

design/mvp/WIT.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,8 @@ transform: func(blob) -> blob
10171017
```
10181018

10191019
As syntactic sugar, resource statements can also declare any number of
1020-
*methods*, which are functions that implicitly takes a `self` borrowed handle
1021-
parameter. A resource statement can also contain any number of *static
1020+
*methods*, which are functions that implicitly take a `self` parameter that is
1021+
a handle. A resource statement can also contain any number of *static
10221022
functions*, which do not have an implicit `self` parameter but are meant to be
10231023
lexically nested in the scope of the resource type. Lastly, a resource
10241024
statement can contain at most one *constructor* function, which is syntactic
@@ -1046,6 +1046,14 @@ bindings generators can generate idiomatic syntax for the target language or
10461046
(for languages like C) fall back to an appropriately-prefixed free function
10471047
name.
10481048

1049+
When a resource type name is used directly (e.g. when `blob` is used as the
1050+
return value of the constructor above), it stands for an "owning" handle
1051+
that will call the resource's destructor when dropped. When a resource
1052+
type name is wrapped with `borrow<...>`, it stands for a "borrowed" handle
1053+
that will *not* call the destructor when dropped. As shown above, methods
1054+
always desugar to a borrowed self parameter whereas constructors always
1055+
desugar to an owned return value.
1056+
10491057
Specifically, the syntax for a `resource` definition is:
10501058
```ebnf
10511059
resource-item ::= 'resource' id resource-methods?
@@ -1055,6 +1063,8 @@ resource-method ::= func-item
10551063
| 'constructor' param-list
10561064
```
10571065

1066+
The syntax for handle types is presented [below](#handles).
1067+
10581068
## Types
10591069

10601070
As mentioned previously the intention of `wit` is to allow defining types

0 commit comments

Comments
 (0)