I understand that it is not possible to "add" backing fields as extensions as described here. Now I found this piece of code in the documentation of the jetpack datastore and don't really understand what's happening. To me it looks like settingsDataStore is an extension field of Context, but that shouldn't be possible...:
val Context.settingsDataStore: DataStore<Settings> by dataStore(
fileName = "settings.pb",
serializer = SettingsSerializer)
Later this "settingsDataStore" is accessed like this:
val exampleCounterFlow: Flow<Int> = context.settingsDataStore.data
.map { settings ->
// The exampleCounter property is generated from the proto schema.
settings.exampleCounter
}
Can someone explain to me what's going on here? How does this work? Are getters and setters somehow provided implicit by "dataStore()"? But where exactly is the actual "settingsDataStore"? It can't really refrence to a field in Context...?