hex/ios/HEXShared/FullKeyboard/KeyboardCore.swift
Sebastian Herrlinger 035b74354e iOS keyboard: KeyboardCoreModel, the Rust core's handle on a typing model
TypingDecoderModel keeps its file's URL and opens the core's model on it on
first use, from any thread. Nothing calls it yet: the keyboard behaves as
before. KeyboardCoreLinkTests checks the core links and reads the bundled
English model.
2026-11-22 13:34:49 +01:00

20 lines
635 B
Swift

import Foundation
import HexKeyboardCore
/// A typing model opened by the keyboard's Rust core (`crates/keyboard`, `hk_model_*`): its
/// own read-only map of the file. It never changes once open, so any thread may use it.
nonisolated final class KeyboardCoreModel: @unchecked Sendable {
/// The core's handle, for the other wrappers of its interface.
let pointer: OpaquePointer
init?(url: URL) {
guard let pointer = hk_model_open(url.path) else { return nil }
self.pointer = pointer
}
deinit {
hk_model_free(pointer)
}
var wordCount: Int { Int(hk_model_word_count(pointer)) }
}