---
source: boltffi_bindgen/src/render/swift/templates.rs
expression: "render_class(&cls, \"boltffi\")"
---
/// A persistent key-value data store.
public final class DataStore {
    let handle: UnsafeMutableRawPointer

    init(handle: UnsafeMutableRawPointer) {
        self.handle = handle
    }

    /// Creates a new data store with the given capacity.
    public init(capacity: Int32) {
        let ptr = boltffi_data_store_new(capacity)!
        self.handle = ptr
    }

    /// Creates a data store with sensible default settings.
    public static func withDefaults() -> DataStore {
        let ptr = boltffi_data_store_with_defaults()!
        return DataStore(handle: ptr)
    }

    deinit {
        boltffi_data_store_free(handle)
    }

    /// Inserts a value into the store by key.
    public func insert(key: String) {
        var key = key
        key.withUTF8 { keyBuf in
            boltffi_data_store_insert(handle, keyBuf.baseAddress!, UInt(keyBuf.count))
        }
    }

}
