An object A
that may be scoped.
An object A
that may be scoped.
A method that accepts a Borrowing parameter must follows all instructions on Scoped resource. However, a method that provides a Borrowing may create it either from GarbageCollectable or from Owned.
An object A
that is managed by garbage collector.
A Scoped resource managed by Owner
.
A Scoped resource managed by Owner
.
It's Owner
's responsibility to close
or release
the underlying resource when exiting the scope.
An resource A
that is only available in certain scope.
An resource A
that is only available in certain scope.
For example, a FileInputStream
that will be automatically close
d when exiting a scope.
val outOfScopeStore = ArrayBuffer.empty[FileInputStream] def read(stream: Scoped[FileInputStream]) = { // OK! You can use a scoped resource inside `read` method stream.read(); // Wrong! A scoped resource should not be stored. outOfScopeStore += stream // Wrong! A scoped resource is managed by another owner. It should not be closed inside the scope. stream.close(); }
You should not store Scoped resource for out-of-scope usage.
Marks a
as garbage collectable.
The name space for types that models ownership of resources.
Author:
杨博 (Yang Bo) <[email protected]>