Add documentation comments and a defaulting subscript to `Storage`.
This patch was authored and released by @gwynne.
The new subscript simplifies "provider" implementations that extend Application
and use its Storage
instance without complex initialization requirements:
extension Application {
public struct Foo {
final class Storage { /* content which needs no special initialization */ }
struct Key: StorageKey { typealias Value = Storage }
let application: Application
// Before:
var storage: Storage {
if self.application.storage[Key.self] == nil { self.initialize() }
return self.application.storage[Key.self]!
}
func initialize() { self.application.storage[Key.self] = .init() }
// After:
var storage: Storage { self.application.storage[Key.self, default: .init()] }