Revision control
Copy as Markdown
// This file was autogenerated by some hot garbage in the `uniffi` crate.
// Trust me, you don't want to mess with it!
// swiftlint:disable all
import Foundation
// Depending on the consumer's build setup, the low-level FFI code
// might be in a separate module, or it might be compiled inline into
// this module. This is a bit of light hackery to work with both.
#if canImport(MozillaRustComponents)
import MozillaRustComponents
#endif
fileprivate extension RustBuffer {
// Allocate a new buffer, copying the contents of a `UInt8` array.
init(bytes: [UInt8]) {
let rbuf = bytes.withUnsafeBufferPointer { ptr in
RustBuffer.from(ptr)
}
self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
}
static func empty() -> RustBuffer {
RustBuffer(capacity: 0, len:0, data: nil)
}
static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
try! rustCall { ffi_ads_client_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
}
// Frees the buffer in place.
// The buffer must not be used after this is called.
func deallocate() {
try! rustCall { ffi_ads_client_rustbuffer_free(self, $0) }
}
}
fileprivate extension ForeignBytes {
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
}
init(rawBufferPointer: UnsafeRawBufferPointer) {
self.init(
len: Int32(rawBufferPointer.count),
data: rawBufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self)
)
}
}
// Converter for `&[u8]` / `[ByRef] bytes` arguments.
//
// Conforms to `FfiConverter` so the compiler enforces the full converter
// method set. Only the scope-bound `lower(_:_body:)` overload is sound —
// zero-copy byte buffers only flow foreign -> Rust, and only in argument
// position. The four protocol-witness methods (`lift`, `lower`, `read`,
// `write`) `fatalError` at runtime if anyone reaches them.
//
// The scope-bound `lower` takes a closure because the `ForeignBytes`
// pointer is only guaranteed valid for the duration of
// `Data.withUnsafeBytes`. Callers must run the full FFI call inside
// the closure body.
fileprivate enum FfiConverterByRefBytes: FfiConverter {
typealias SwiftType = Data
typealias FfiType = ForeignBytes
static func lower<R>(_ value: Data, _ body: (ForeignBytes) throws -> R) rethrows -> R {
return try value.withUnsafeBytes { rawBuf in
try body(ForeignBytes(rawBufferPointer: rawBuf))
}
}
static func lower(_ value: Data) -> ForeignBytes {
fatalError("ByRef bytes cannot use the plain lower: returning ForeignBytes escapes the Data.withUnsafeBytes scope. Use the scope-bound lower(_:_body:) overload instead.")
}
static func lift(_ value: ForeignBytes) throws -> Data {
fatalError("ByRef bytes cannot be lifted: zero-copy &[u8] only flows foreign->Rust")
}
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
fatalError("ByRef bytes cannot be read from a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
}
static func write(_ value: Data, into buf: inout [UInt8]) {
fatalError("ByRef bytes cannot be written to a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
}
}
// For every type used in the interface, we provide helper methods for conveniently
// lifting and lowering that type from C-compatible data, and for reading and writing
// values of that type in a buffer.
// Helper classes/extensions that don't change.
// Someday, this will be in a library of its own.
fileprivate extension Data {
init(rustBuffer: RustBuffer) {
self.init(
bytesNoCopy: rustBuffer.data!,
count: Int(rustBuffer.len),
deallocator: .none
)
}
}
// Define reader functionality. Normally this would be defined in a class or
// struct, but we use standalone functions instead in order to make external
// types work.
//
// With external types, one swift source file needs to be able to call the read
// method on another source file's FfiConverter, but then what visibility
// should Reader have?
// - If Reader is fileprivate, then this means the read() must also
// be fileprivate, which doesn't work with external types.
// - If Reader is internal/public, we'll get compile errors since both source
// files will try define the same type.
//
// Instead, the read() method and these helper functions input a tuple of data
fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
(data: data, offset: 0)
}
// Reads an integer at the current offset, in big-endian order, and advances
// the offset on success. Throws if reading the integer would move the
// offset past the end of the buffer.
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
let range = reader.offset..<reader.offset + MemoryLayout<T>.size
guard reader.data.count >= range.upperBound else {
throw UniffiInternalError.bufferOverflow
}
if T.self == UInt8.self {
let value = reader.data[reader.offset]
reader.offset += 1
return value as! T
}
var value: T = 0
let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
reader.offset = range.upperBound
return value.bigEndian
}
// Reads an arbitrary number of bytes, to be used to read
// raw bytes, this is useful when lifting strings
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
let range = reader.offset..<(reader.offset+count)
guard reader.data.count >= range.upperBound else {
throw UniffiInternalError.bufferOverflow
}
var value = [UInt8](repeating: 0, count: count)
value.withUnsafeMutableBufferPointer({ buffer in
reader.data.copyBytes(to: buffer, from: range)
})
reader.offset = range.upperBound
return value
}
// Reads a float at the current offset.
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
return Float(bitPattern: try readInt(&reader))
}
// Reads a float at the current offset.
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
return Double(bitPattern: try readInt(&reader))
}
// Indicates if the offset has reached the end of the buffer.
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
return reader.offset < reader.data.count
}
// Define writer functionality. Normally this would be defined in a class or
// struct, but we use standalone functions instead in order to make external
// types work. See the above discussion on Readers for details.
fileprivate func createWriter() -> [UInt8] {
return []
}
fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
writer.append(contentsOf: byteArr)
}
// Writes an integer in big-endian order.
//
// Warning: make sure what you are trying to write
// is in the correct type!
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
var value = value.bigEndian
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
}
fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
writeInt(&writer, value.bitPattern)
}
fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
writeInt(&writer, value.bitPattern)
}
// Protocol for types that transfer other types across the FFI. This is
// analogous to the Rust trait of the same name.
fileprivate protocol FfiConverter {
associatedtype FfiType
associatedtype SwiftType
static func lift(_ value: FfiType) throws -> SwiftType
static func lower(_ value: SwiftType) -> FfiType
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
static func write(_ value: SwiftType, into buf: inout [UInt8])
}
// Types conforming to `Primitive` pass themselves directly over the FFI.
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
extension FfiConverterPrimitive {
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lift(_ value: FfiType) throws -> SwiftType {
return value
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lower(_ value: SwiftType) -> FfiType {
return value
}
}
// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
// Used for complex types where it's hard to write a custom lift/lower.
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
extension FfiConverterRustBuffer {
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
var reader = createReader(data: Data(rustBuffer: buf))
let value = try read(from: &reader)
if hasRemaining(reader) {
throw UniffiInternalError.incompleteData
}
buf.deallocate()
return value
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lower(_ value: SwiftType) -> RustBuffer {
var writer = createWriter()
write(value, into: &writer)
return RustBuffer(bytes: writer)
}
}
// An error type for FFI errors. These errors occur at the UniFFI level, not
// the library level.
fileprivate enum UniffiInternalError: LocalizedError {
case bufferOverflow
case incompleteData
case unexpectedOptionalTag
case unexpectedEnumCase
case unexpectedNullPointer
case unexpectedRustCallStatusCode
case unexpectedRustCallError
case unexpectedStaleHandle
case rustPanic(_ message: String)
public var errorDescription: String? {
switch self {
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
case .incompleteData: return "The buffer still has data after lifting its containing value"
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
case .unexpectedNullPointer: return "Raw pointer value was null"
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
case let .rustPanic(message): return message
}
}
}
fileprivate extension NSLock {
func withLock<T>(f: () throws -> T) rethrows -> T {
self.lock()
defer { self.unlock() }
return try f()
}
}
fileprivate let CALL_SUCCESS: Int8 = 0
fileprivate let CALL_ERROR: Int8 = 1
fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
fileprivate let CALL_CANCELLED: Int8 = 3
fileprivate extension RustCallStatus {
init() {
self.init(
code: CALL_SUCCESS,
errorBuf: RustBuffer.init(
capacity: 0,
len: 0,
data: nil
)
)
}
}
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
let neverThrow: ((RustBuffer) throws -> Never)? = nil
return try makeRustCall(callback, errorHandler: neverThrow)
}
private func rustCallWithError<T, E: Swift.Error>(
_ errorHandler: @escaping (RustBuffer) throws -> E,
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
try makeRustCall(callback, errorHandler: errorHandler)
}
private func makeRustCall<T, E: Swift.Error>(
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
errorHandler: ((RustBuffer) throws -> E)?
) throws -> T {
uniffiEnsureAdsClientInitialized()
var callStatus = RustCallStatus.init()
let returnedVal = callback(&callStatus)
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
return returnedVal
}
private func uniffiCheckCallStatus<E: Swift.Error>(
callStatus: RustCallStatus,
errorHandler: ((RustBuffer) throws -> E)?
) throws {
switch callStatus.code {
case CALL_SUCCESS:
return
case CALL_ERROR:
if let errorHandler = errorHandler {
throw try errorHandler(callStatus.errorBuf)
} else {
callStatus.errorBuf.deallocate()
throw UniffiInternalError.unexpectedRustCallError
}
case CALL_UNEXPECTED_ERROR:
// When the rust code sees a panic, it tries to construct a RustBuffer
// with the message. But if that code panics, then it just sends back
// an empty buffer.
if callStatus.errorBuf.len > 0 {
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
} else {
callStatus.errorBuf.deallocate()
throw UniffiInternalError.rustPanic("Rust panic")
}
case CALL_CANCELLED:
fatalError("Cancellation not supported yet")
default:
throw UniffiInternalError.unexpectedRustCallStatusCode
}
}
private func uniffiTraitInterfaceCall<T>(
callStatus: UnsafeMutablePointer<RustCallStatus>,
makeCall: () throws -> T,
writeReturn: (T) -> ()
) {
do {
try writeReturn(makeCall())
} catch let error {
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
}
}
private func uniffiTraitInterfaceCallWithError<T, E>(
callStatus: UnsafeMutablePointer<RustCallStatus>,
makeCall: () throws -> T,
writeReturn: (T) -> (),
lowerError: (E) -> RustBuffer
) {
do {
try writeReturn(makeCall())
} catch let error as E {
callStatus.pointee.code = CALL_ERROR
callStatus.pointee.errorBuf = lowerError(error)
} catch {
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
}
}
// Initial value and increment amount for handles.
// These ensure that SWIFT handles always have the lowest bit set
fileprivate let UNIFFI_HANDLEMAP_INITIAL: UInt64 = 1
fileprivate let UNIFFI_HANDLEMAP_DELTA: UInt64 = 2
fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
// All mutation happens with this lock held, which is why we implement @unchecked Sendable.
private let lock = NSLock()
private var map: [UInt64: T] = [:]
private var currentHandle: UInt64 = UNIFFI_HANDLEMAP_INITIAL
func insert(obj: T) -> UInt64 {
lock.withLock {
return doInsert(obj)
}
}
// Low-level insert function, this assumes `lock` is held.
private func doInsert(_ obj: T) -> UInt64 {
let handle = currentHandle
currentHandle += UNIFFI_HANDLEMAP_DELTA
map[handle] = obj
return handle
}
func get(handle: UInt64) throws -> T {
try lock.withLock {
guard let obj = map[handle] else {
throw UniffiInternalError.unexpectedStaleHandle
}
return obj
}
}
func clone(handle: UInt64) throws -> UInt64 {
try lock.withLock {
guard let obj = map[handle] else {
throw UniffiInternalError.unexpectedStaleHandle
}
return doInsert(obj)
}
}
@discardableResult
func remove(handle: UInt64) throws -> T {
try lock.withLock {
guard let obj = map.removeValue(forKey: handle) else {
throw UniffiInternalError.unexpectedStaleHandle
}
return obj
}
}
var count: Int {
get {
map.count
}
}
}
// Public interface members begin here.
// Magic number for the Rust proxy to call using the same mechanism as every other method,
// to free the callback once it's dropped by Rust.
private let IDX_CALLBACK_FREE: Int32 = 0
// Callback return codes
private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
private let UNIFFI_CALLBACK_ERROR: Int32 = 1
private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
typealias FfiType = UInt32
typealias SwiftType = UInt32
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
return try lift(readInt(&buf))
}
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterUInt64: FfiConverterPrimitive {
typealias FfiType = UInt64
typealias SwiftType = UInt64
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 {
return try lift(readInt(&buf))
}
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDouble: FfiConverterPrimitive {
typealias FfiType = Double
typealias SwiftType = Double
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Double {
return try lift(readDouble(&buf))
}
public static func write(_ value: Double, into buf: inout [UInt8]) {
writeDouble(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterBool : FfiConverter {
typealias FfiType = Int8
typealias SwiftType = Bool
public static func lift(_ value: Int8) throws -> Bool {
return value != 0
}
public static func lower(_ value: Bool) -> Int8 {
return value ? 1 : 0
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
return try lift(readInt(&buf))
}
public static func write(_ value: Bool, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterString: FfiConverter {
typealias SwiftType = String
typealias FfiType = RustBuffer
public static func lift(_ value: RustBuffer) throws -> String {
defer {
value.deallocate()
}
if value.data == nil {
return String()
}
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
// Use Swift's native UTF-8 decoder; `String(bytes:encoding:.utf8)` goes
// through Foundation's NSString and silently strips a leading U+FEFF BOM.
// Invalid UTF-8 substitutes U+FFFD instead of trapping (unreachable
// given Rust's `String` invariant).
return String(decoding: bytes, as: UTF8.self)
}
public static func lower(_ value: String) -> RustBuffer {
return value.utf8CString.withUnsafeBufferPointer { ptr in
// The swift string gives us int8_t, we want uint8_t.
ptr.withMemoryRebound(to: UInt8.self) { ptr in
// The swift string gives us a trailing null byte, we don't want it.
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
return RustBuffer.from(buf)
}
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
let len: Int32 = try readInt(&buf)
// See `lift` above for why we avoid Foundation's NSString-backed decoder here.
return String(decoding: try readBytes(&buf, count: Int(len)), as: UTF8.self)
}
public static func write(_ value: String, into buf: inout [UInt8]) {
let len = Int32(value.utf8.count)
writeInt(&buf, len)
writeBytes(&buf, value.utf8)
}
}
/**
* Requests ads from MARS and records their clicks, impressions and reports.
* Build it with [`MozAdsClientBuilder`], ideally once per app.
*/
public protocol MozAdsClientProtocol: AnyObject, Sendable {
/**
* Deletes everything in the HTTP cache.
*/
func clearCache() throws
/**
* Records a click on an ad, from its `callbacks.click` URL.
*/
func recordClick(clickUrl: String, options: MozAdsCallbackOptions?) throws
/**
* Records an impression of an ad, from its `callbacks.impression` URL.
*/
func recordImpression(impressionUrl: String, options: MozAdsCallbackOptions?) throws
/**
* Reports an ad, from its `callbacks.report` URL.
*/
func reportAd(reportUrl: String, reason: MozAdsReportReason, options: MozAdsCallbackOptions?) throws
/**
* Requests one image ad per placement. The result is keyed by
* `placement_id` and leaves out placements with no ad.
*/
func requestImageAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions?) throws -> [String: MozAdsImage]
/**
* Requests `count` spocs per placement. The result is keyed by
* `placement_id` and leaves out placements with no ad.
*/
func requestSpocAds(mozAdRequests: [MozAdsPlacementRequestWithCount], options: MozAdsRequestOptions?) throws -> [String: [MozAdsSpoc]]
/**
* Requests `count` ads per placement, for placements that can return
* either spocs or image ads. The result is keyed by `placement_id` and
* leaves out placements with no ad.
*/
func requestSpocOrImageAds(mozAdRequests: [MozAdsPlacementRequestWithCount], options: MozAdsRequestOptions?) throws -> [String: [MozAdsImageOrSpoc]]
/**
* Requests one tile ad per placement. The result is keyed by
* `placement_id` and leaves out placements with no ad.
*/
func requestTileAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions?) throws -> [String: MozAdsTile]
/**
* Allows the ads-client to unload some references and prepare for a safe shutdown.
* Other methods should not be called after this one.
* Currently, we shutdown (with no expected errors).
* However, future shutdowns may require an error to be logged, so we keep the Result.
*/
func shutdown() throws
}
/**
* Requests ads from MARS and records their clicks, impressions and reports.
* Build it with [`MozAdsClientBuilder`], ideally once per app.
*/
open class MozAdsClient: MozAdsClientProtocol, @unchecked Sendable {
fileprivate let handle: UInt64
/// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct NoHandle {
public init() {}
}
// TODO: We'd like this to be `private` but for Swifty reasons,
// we can't implement `FfiConverter` without making this `required` and we can't
// make it `required` without making it `public`.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
required public init(unsafeFromHandle handle: UInt64) {
self.handle = handle
}
// This constructor can be used to instantiate a fake object.
// - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
//
// - Warning:
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public init(noHandle: NoHandle) {
self.handle = 0
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func uniffiCloneHandle() -> UInt64 {
return try! rustCall { uniffi_ads_client_fn_clone_mozadsclient(self.handle, $0) }
}
// No primary constructor declared for this class.
deinit {
if handle == 0 {
// Mock objects have handle=0 don't try to free them
return
}
try! rustCall { uniffi_ads_client_fn_free_mozadsclient(handle, $0) }
}
/**
* Deletes everything in the HTTP cache.
*/
open func clearCache()throws {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_clear_cache(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Records a click on an ad, from its `callbacks.click` URL.
*/
open func recordClick(clickUrl: String, options: MozAdsCallbackOptions? = nil)throws {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_record_click(
self.uniffiCloneHandle(),
FfiConverterString.lower(clickUrl),
FfiConverterOptionTypeMozAdsCallbackOptions.lower(options),uniffiCallStatus
)
}
}
/**
* Records an impression of an ad, from its `callbacks.impression` URL.
*/
open func recordImpression(impressionUrl: String, options: MozAdsCallbackOptions? = nil)throws {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_record_impression(
self.uniffiCloneHandle(),
FfiConverterString.lower(impressionUrl),
FfiConverterOptionTypeMozAdsCallbackOptions.lower(options),uniffiCallStatus
)
}
}
/**
* Reports an ad, from its `callbacks.report` URL.
*/
open func reportAd(reportUrl: String, reason: MozAdsReportReason, options: MozAdsCallbackOptions? = nil)throws {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_report_ad(
self.uniffiCloneHandle(),
FfiConverterString.lower(reportUrl),
FfiConverterTypeMozAdsReportReason_lower(reason),
FfiConverterOptionTypeMozAdsCallbackOptions.lower(options),uniffiCallStatus
)
}
}
/**
* Requests one image ad per placement. The result is keyed by
* `placement_id` and leaves out placements with no ad.
*/
open func requestImageAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions? = nil)throws -> [String: MozAdsImage] {
return try FfiConverterDictionaryStringTypeMozAdsImage.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_request_image_ads(
self.uniffiCloneHandle(),
FfiConverterSequenceTypeMozAdsPlacementRequest.lower(mozAdRequests),
FfiConverterOptionTypeMozAdsRequestOptions.lower(options),uniffiCallStatus
)
})
}
/**
* Requests `count` spocs per placement. The result is keyed by
* `placement_id` and leaves out placements with no ad.
*/
open func requestSpocAds(mozAdRequests: [MozAdsPlacementRequestWithCount], options: MozAdsRequestOptions? = nil)throws -> [String: [MozAdsSpoc]] {
return try FfiConverterDictionaryStringSequenceTypeMozAdsSpoc.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_request_spoc_ads(
self.uniffiCloneHandle(),
FfiConverterSequenceTypeMozAdsPlacementRequestWithCount.lower(mozAdRequests),
FfiConverterOptionTypeMozAdsRequestOptions.lower(options),uniffiCallStatus
)
})
}
/**
* Requests `count` ads per placement, for placements that can return
* either spocs or image ads. The result is keyed by `placement_id` and
* leaves out placements with no ad.
*/
open func requestSpocOrImageAds(mozAdRequests: [MozAdsPlacementRequestWithCount], options: MozAdsRequestOptions? = nil)throws -> [String: [MozAdsImageOrSpoc]] {
return try FfiConverterDictionaryStringSequenceTypeMozAdsImageOrSpoc.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_request_spoc_or_image_ads(
self.uniffiCloneHandle(),
FfiConverterSequenceTypeMozAdsPlacementRequestWithCount.lower(mozAdRequests),
FfiConverterOptionTypeMozAdsRequestOptions.lower(options),uniffiCallStatus
)
})
}
/**
* Requests one tile ad per placement. The result is keyed by
* `placement_id` and leaves out placements with no ad.
*/
open func requestTileAds(mozAdRequests: [MozAdsPlacementRequest], options: MozAdsRequestOptions? = nil)throws -> [String: MozAdsTile] {
return try FfiConverterDictionaryStringTypeMozAdsTile.lift(try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_request_tile_ads(
self.uniffiCloneHandle(),
FfiConverterSequenceTypeMozAdsPlacementRequest.lower(mozAdRequests),
FfiConverterOptionTypeMozAdsRequestOptions.lower(options),uniffiCallStatus
)
})
}
/**
* Allows the ads-client to unload some references and prepare for a safe shutdown.
* Other methods should not be called after this one.
* Currently, we shutdown (with no expected errors).
* However, future shutdowns may require an error to be logged, so we keep the Result.
*/
open func shutdown()throws {try rustCallWithError(FfiConverterTypeMozAdsClientApiError_lift) {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclient_shutdown(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsClient: FfiConverter {
typealias FfiType = UInt64
typealias SwiftType = MozAdsClient
public static func lift(_ handle: UInt64) throws -> MozAdsClient {
return MozAdsClient(unsafeFromHandle: handle)
}
public static func lower(_ value: MozAdsClient) -> UInt64 {
return value.uniffiCloneHandle()
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsClient {
let handle: UInt64 = try readInt(&buf)
return try lift(handle)
}
public static func write(_ value: MozAdsClient, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClient_lift(_ handle: UInt64) throws -> MozAdsClient {
return try FfiConverterTypeMozAdsClient.lift(handle)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClient_lower(_ value: MozAdsClient) -> UInt64 {
return FfiConverterTypeMozAdsClient.lower(value)
}
/**
* Configures and builds a [`MozAdsClient`].
*/
public protocol MozAdsClientBuilderProtocol: AnyObject, Sendable {
/**
* Builds the client. A telemetry instance set on the builder becomes the
* destination of every client's metrics in the process.
*/
func build() -> MozAdsClient
/**
* Enables the HTTP cache with this configuration. Without it, nothing is
* cached.
*/
func cacheConfig(cacheConfig: MozAdsCacheConfig) -> MozAdsClientBuilder
/**
* The MARS environment to send requests to. Defaults to production.
*/
func environment(environment: MozAdsEnvironment) -> MozAdsClientBuilder
/**
* Where the client records its metrics. Telemetry is process-wide: see
* [`MozAdsTelemetry`].
*/
func telemetry(telemetry: MozAdsTelemetry) -> MozAdsClientBuilder
/**
* The browser's user agent, sent to MARS on OHTTP requests when the
* preflight returns none. Defaults to viaduct's global default user agent.
*/
func userAgent(userAgent: String) -> MozAdsClientBuilder
}
/**
* Configures and builds a [`MozAdsClient`].
*/
open class MozAdsClientBuilder: MozAdsClientBuilderProtocol, @unchecked Sendable {
fileprivate let handle: UInt64
/// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct NoHandle {
public init() {}
}
// TODO: We'd like this to be `private` but for Swifty reasons,
// we can't implement `FfiConverter` without making this `required` and we can't
// make it `required` without making it `public`.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
required public init(unsafeFromHandle handle: UInt64) {
self.handle = handle
}
// This constructor can be used to instantiate a fake object.
// - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
//
// - Warning:
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public init(noHandle: NoHandle) {
self.handle = 0
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func uniffiCloneHandle() -> UInt64 {
return try! rustCall { uniffi_ads_client_fn_clone_mozadsclientbuilder(self.handle, $0) }
}
/**
* A builder with the defaults: the production environment, no cache and
* no telemetry.
*/
public convenience init() {
let handle =
try! rustCall() {
uniffiCallStatus in
uniffi_ads_client_fn_constructor_mozadsclientbuilder_new(uniffiCallStatus
)
}
self.init(unsafeFromHandle: handle)
}
deinit {
if handle == 0 {
// Mock objects have handle=0 don't try to free them
return
}
try! rustCall { uniffi_ads_client_fn_free_mozadsclientbuilder(handle, $0) }
}
/**
* Builds the client. A telemetry instance set on the builder becomes the
* destination of every client's metrics in the process.
*/
open func build() -> MozAdsClient {
return try! FfiConverterTypeMozAdsClient_lift(try! rustCall() {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclientbuilder_build(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Enables the HTTP cache with this configuration. Without it, nothing is
* cached.
*/
open func cacheConfig(cacheConfig: MozAdsCacheConfig) -> MozAdsClientBuilder {
return try! FfiConverterTypeMozAdsClientBuilder_lift(try! rustCall() {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclientbuilder_cache_config(
self.uniffiCloneHandle(),
FfiConverterTypeMozAdsCacheConfig_lower(cacheConfig),uniffiCallStatus
)
})
}
/**
* The MARS environment to send requests to. Defaults to production.
*/
open func environment(environment: MozAdsEnvironment) -> MozAdsClientBuilder {
return try! FfiConverterTypeMozAdsClientBuilder_lift(try! rustCall() {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclientbuilder_environment(
self.uniffiCloneHandle(),
FfiConverterTypeMozAdsEnvironment_lower(environment),uniffiCallStatus
)
})
}
/**
* Where the client records its metrics. Telemetry is process-wide: see
* [`MozAdsTelemetry`].
*/
open func telemetry(telemetry: MozAdsTelemetry) -> MozAdsClientBuilder {
return try! FfiConverterTypeMozAdsClientBuilder_lift(try! rustCall() {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclientbuilder_telemetry(
self.uniffiCloneHandle(),
FfiConverterCallbackInterfaceMozAdsTelemetry_lower(telemetry),uniffiCallStatus
)
})
}
/**
* The browser's user agent, sent to MARS on OHTTP requests when the
* preflight returns none. Defaults to viaduct's global default user agent.
*/
open func userAgent(userAgent: String) -> MozAdsClientBuilder {
return try! FfiConverterTypeMozAdsClientBuilder_lift(try! rustCall() {
uniffiCallStatus in
uniffi_ads_client_fn_method_mozadsclientbuilder_user_agent(
self.uniffiCloneHandle(),
FfiConverterString.lower(userAgent),uniffiCallStatus
)
})
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsClientBuilder: FfiConverter {
typealias FfiType = UInt64
typealias SwiftType = MozAdsClientBuilder
public static func lift(_ handle: UInt64) throws -> MozAdsClientBuilder {
return MozAdsClientBuilder(unsafeFromHandle: handle)
}
public static func lower(_ value: MozAdsClientBuilder) -> UInt64 {
return value.uniffiCloneHandle()
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsClientBuilder {
let handle: UInt64 = try readInt(&buf)
return try lift(handle)
}
public static func write(_ value: MozAdsClientBuilder, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClientBuilder_lift(_ handle: UInt64) throws -> MozAdsClientBuilder {
return try FfiConverterTypeMozAdsClientBuilder.lift(handle)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClientBuilder_lower(_ value: MozAdsClientBuilder) -> UInt64 {
return FfiConverterTypeMozAdsClientBuilder.lower(value)
}
/**
* The on-disk HTTP cache. `default_cache_ttl_seconds` defaults to 300 and
* `max_size_mib` to 10.
*/
public struct MozAdsCacheConfig: Equatable, Hashable {
public var dbPath: String
public var defaultCacheTtlSeconds: UInt64?
public var maxSizeMib: UInt64?
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(dbPath: String, defaultCacheTtlSeconds: UInt64? = nil, maxSizeMib: UInt64? = nil) {
self.dbPath = dbPath
self.defaultCacheTtlSeconds = defaultCacheTtlSeconds
self.maxSizeMib = maxSizeMib
}
}
#if compiler(>=6)
extension MozAdsCacheConfig: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCacheConfig: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCacheConfig {
return
try MozAdsCacheConfig(
dbPath: FfiConverterString.read(from: &buf),
defaultCacheTtlSeconds: FfiConverterOptionUInt64.read(from: &buf),
maxSizeMib: FfiConverterOptionUInt64.read(from: &buf)
)
}
public static func write(_ value: MozAdsCacheConfig, into buf: inout [UInt8]) {
FfiConverterString.write(value.dbPath, into: &buf)
FfiConverterOptionUInt64.write(value.defaultCacheTtlSeconds, into: &buf)
FfiConverterOptionUInt64.write(value.maxSizeMib, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCacheConfig_lift(_ buf: RustBuffer) throws -> MozAdsCacheConfig {
return try FfiConverterTypeMozAdsCacheConfig.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCacheConfig_lower(_ value: MozAdsCacheConfig) -> RustBuffer {
return FfiConverterTypeMozAdsCacheConfig.lower(value)
}
/**
* How one request uses the cache. `ttl_seconds` overrides the client's
* default TTL; `0` does not cache the response.
*/
public struct MozAdsCachePolicy: Equatable, Hashable {
public var mode: MozAdsCacheMode
public var ttlSeconds: UInt64?
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(mode: MozAdsCacheMode, ttlSeconds: UInt64? = nil) {
self.mode = mode
self.ttlSeconds = ttlSeconds
}
}
#if compiler(>=6)
extension MozAdsCachePolicy: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCachePolicy: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCachePolicy {
return
try MozAdsCachePolicy(
mode: FfiConverterTypeMozAdsCacheMode.read(from: &buf),
ttlSeconds: FfiConverterOptionUInt64.read(from: &buf)
)
}
public static func write(_ value: MozAdsCachePolicy, into buf: inout [UInt8]) {
FfiConverterTypeMozAdsCacheMode.write(value.mode, into: &buf)
FfiConverterOptionUInt64.write(value.ttlSeconds, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCachePolicy_lift(_ buf: RustBuffer) throws -> MozAdsCachePolicy {
return try FfiConverterTypeMozAdsCachePolicy.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCachePolicy_lower(_ value: MozAdsCachePolicy) -> RustBuffer {
return FfiConverterTypeMozAdsCachePolicy.lower(value)
}
/**
* Options for a callback request (click, impression or report).
*/
public struct MozAdsCallbackOptions: Equatable, Hashable {
public var ohttp: Bool
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(ohttp: Bool = false) {
self.ohttp = ohttp
}
}
#if compiler(>=6)
extension MozAdsCallbackOptions: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCallbackOptions: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCallbackOptions {
return
try MozAdsCallbackOptions(
ohttp: FfiConverterBool.read(from: &buf)
)
}
public static func write(_ value: MozAdsCallbackOptions, into buf: inout [UInt8]) {
FfiConverterBool.write(value.ohttp, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCallbackOptions_lift(_ buf: RustBuffer) throws -> MozAdsCallbackOptions {
return try FfiConverterTypeMozAdsCallbackOptions.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCallbackOptions_lower(_ value: MozAdsCallbackOptions) -> RustBuffer {
return FfiConverterTypeMozAdsCallbackOptions.lower(value)
}
/**
* The callback URLs of an ad: pass them to `record_click`,
* `record_impression` and `report_ad`.
*/
public struct MozAdsCallbacks: Equatable, Hashable {
public var click: AdsClientUrl
public var impression: AdsClientUrl
public var report: AdsClientUrl?
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(click: AdsClientUrl, impression: AdsClientUrl, report: AdsClientUrl?) {
self.click = click
self.impression = impression
self.report = report
}
}
#if compiler(>=6)
extension MozAdsCallbacks: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCallbacks: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCallbacks {
return
try MozAdsCallbacks(
click: FfiConverterTypeAdsClientUrl.read(from: &buf),
impression: FfiConverterTypeAdsClientUrl.read(from: &buf),
report: FfiConverterOptionTypeAdsClientUrl.read(from: &buf)
)
}
public static func write(_ value: MozAdsCallbacks, into buf: inout [UInt8]) {
FfiConverterTypeAdsClientUrl.write(value.click, into: &buf)
FfiConverterTypeAdsClientUrl.write(value.impression, into: &buf)
FfiConverterOptionTypeAdsClientUrl.write(value.report, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCallbacks_lift(_ buf: RustBuffer) throws -> MozAdsCallbacks {
return try FfiConverterTypeMozAdsCallbacks.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCallbacks_lower(_ value: MozAdsCallbacks) -> RustBuffer {
return FfiConverterTypeMozAdsCallbacks.lower(value)
}
/**
* IAB content categories, in one taxonomy version.
*/
public struct MozAdsContentCategory: Equatable, Hashable {
public var categories: [String]
public var taxonomy: MozAdsIabContentTaxonomy
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(categories: [String], taxonomy: MozAdsIabContentTaxonomy) {
self.categories = categories
self.taxonomy = taxonomy
}
}
#if compiler(>=6)
extension MozAdsContentCategory: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsContentCategory: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsContentCategory {
return
try MozAdsContentCategory(
categories: FfiConverterSequenceString.read(from: &buf),
taxonomy: FfiConverterTypeMozAdsIABContentTaxonomy.read(from: &buf)
)
}
public static func write(_ value: MozAdsContentCategory, into buf: inout [UInt8]) {
FfiConverterSequenceString.write(value.categories, into: &buf)
FfiConverterTypeMozAdsIABContentTaxonomy.write(value.taxonomy, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsContentCategory_lift(_ buf: RustBuffer) throws -> MozAdsContentCategory {
return try FfiConverterTypeMozAdsContentCategory.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsContentCategory_lower(_ value: MozAdsContentCategory) -> RustBuffer {
return FfiConverterTypeMozAdsContentCategory.lower(value)
}
/**
* The IAB content classification of a placement, for targeting.
*/
public struct MozAdsIabContent: Equatable, Hashable {
public var categoryIds: [String]
public var taxonomy: MozAdsIabContentTaxonomy
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(categoryIds: [String], taxonomy: MozAdsIabContentTaxonomy) {
self.categoryIds = categoryIds
self.taxonomy = taxonomy
}
}
#if compiler(>=6)
extension MozAdsIabContent: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsIABContent: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsIabContent {
return
try MozAdsIabContent(
categoryIds: FfiConverterSequenceString.read(from: &buf),
taxonomy: FfiConverterTypeMozAdsIABContentTaxonomy.read(from: &buf)
)
}
public static func write(_ value: MozAdsIabContent, into buf: inout [UInt8]) {
FfiConverterSequenceString.write(value.categoryIds, into: &buf)
FfiConverterTypeMozAdsIABContentTaxonomy.write(value.taxonomy, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsIABContent_lift(_ buf: RustBuffer) throws -> MozAdsIabContent {
return try FfiConverterTypeMozAdsIABContent.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsIABContent_lower(_ value: MozAdsIabContent) -> RustBuffer {
return FfiConverterTypeMozAdsIABContent.lower(value)
}
/**
* An image ad returned by MARS.
*/
public struct MozAdsImage: Equatable, Hashable {
public var altText: String?
public var blockKey: String
public var callbacks: MozAdsCallbacks
public var format: String
public var imageUrl: AdsClientUrl
public var url: AdsClientUrl
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(altText: String?, blockKey: String, callbacks: MozAdsCallbacks, format: String, imageUrl: AdsClientUrl, url: AdsClientUrl) {
self.altText = altText
self.blockKey = blockKey
self.callbacks = callbacks
self.format = format
self.imageUrl = imageUrl
self.url = url
}
}
#if compiler(>=6)
extension MozAdsImage: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsImage: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsImage {
return
try MozAdsImage(
altText: FfiConverterOptionString.read(from: &buf),
blockKey: FfiConverterString.read(from: &buf),
callbacks: FfiConverterTypeMozAdsCallbacks.read(from: &buf),
format: FfiConverterString.read(from: &buf),
imageUrl: FfiConverterTypeAdsClientUrl.read(from: &buf),
url: FfiConverterTypeAdsClientUrl.read(from: &buf)
)
}
public static func write(_ value: MozAdsImage, into buf: inout [UInt8]) {
FfiConverterOptionString.write(value.altText, into: &buf)
FfiConverterString.write(value.blockKey, into: &buf)
FfiConverterTypeMozAdsCallbacks.write(value.callbacks, into: &buf)
FfiConverterString.write(value.format, into: &buf)
FfiConverterTypeAdsClientUrl.write(value.imageUrl, into: &buf)
FfiConverterTypeAdsClientUrl.write(value.url, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsImage_lift(_ buf: RustBuffer) throws -> MozAdsImage {
return try FfiConverterTypeMozAdsImage.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsImage_lower(_ value: MozAdsImage) -> RustBuffer {
return FfiConverterTypeMozAdsImage.lower(value)
}
/**
* One placement to request a single ad for. `placement_id` must be unique
* within one request.
*/
public struct MozAdsPlacementRequest: Equatable, Hashable {
public var iabContent: MozAdsIabContent?
public var placementId: String
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(iabContent: MozAdsIabContent? = nil, placementId: String) {
self.iabContent = iabContent
self.placementId = placementId
}
}
#if compiler(>=6)
extension MozAdsPlacementRequest: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsPlacementRequest: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsPlacementRequest {
return
try MozAdsPlacementRequest(
iabContent: FfiConverterOptionTypeMozAdsIABContent.read(from: &buf),
placementId: FfiConverterString.read(from: &buf)
)
}
public static func write(_ value: MozAdsPlacementRequest, into buf: inout [UInt8]) {
FfiConverterOptionTypeMozAdsIABContent.write(value.iabContent, into: &buf)
FfiConverterString.write(value.placementId, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsPlacementRequest_lift(_ buf: RustBuffer) throws -> MozAdsPlacementRequest {
return try FfiConverterTypeMozAdsPlacementRequest.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsPlacementRequest_lower(_ value: MozAdsPlacementRequest) -> RustBuffer {
return FfiConverterTypeMozAdsPlacementRequest.lower(value)
}
/**
* One placement to request `count` ads for. `placement_id` must be unique
* within one request.
*/
public struct MozAdsPlacementRequestWithCount: Equatable, Hashable {
public var count: UInt32
public var iabContent: MozAdsIabContent?
public var placementId: String
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(count: UInt32, iabContent: MozAdsIabContent? = nil, placementId: String) {
self.count = count
self.iabContent = iabContent
self.placementId = placementId
}
}
#if compiler(>=6)
extension MozAdsPlacementRequestWithCount: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsPlacementRequestWithCount: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsPlacementRequestWithCount {
return
try MozAdsPlacementRequestWithCount(
count: FfiConverterUInt32.read(from: &buf),
iabContent: FfiConverterOptionTypeMozAdsIABContent.read(from: &buf),
placementId: FfiConverterString.read(from: &buf)
)
}
public static func write(_ value: MozAdsPlacementRequestWithCount, into buf: inout [UInt8]) {
FfiConverterUInt32.write(value.count, into: &buf)
FfiConverterOptionTypeMozAdsIABContent.write(value.iabContent, into: &buf)
FfiConverterString.write(value.placementId, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsPlacementRequestWithCount_lift(_ buf: RustBuffer) throws -> MozAdsPlacementRequestWithCount {
return try FfiConverterTypeMozAdsPlacementRequestWithCount.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsPlacementRequestWithCount_lower(_ value: MozAdsPlacementRequestWithCount) -> RustBuffer {
return FfiConverterTypeMozAdsPlacementRequestWithCount.lower(value)
}
/**
* Options for one ad request. Every field has a default.
*/
public struct MozAdsRequestOptions: Equatable, Hashable {
public var blocks: [String]
public var cachePolicy: MozAdsCachePolicy?
public var flags: [String: Bool]
public var ohttp: Bool
public var relevance: [String: Double]
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(blocks: [String] = [], cachePolicy: MozAdsCachePolicy? = nil, flags: [String: Bool] = [:], ohttp: Bool = false, relevance: [String: Double] = [:]) {
self.blocks = blocks
self.cachePolicy = cachePolicy
self.flags = flags
self.ohttp = ohttp
self.relevance = relevance
}
}
#if compiler(>=6)
extension MozAdsRequestOptions: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsRequestOptions: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsRequestOptions {
return
try MozAdsRequestOptions(
blocks: FfiConverterSequenceString.read(from: &buf),
cachePolicy: FfiConverterOptionTypeMozAdsCachePolicy.read(from: &buf),
flags: FfiConverterDictionaryStringBool.read(from: &buf),
ohttp: FfiConverterBool.read(from: &buf),
relevance: FfiConverterDictionaryStringDouble.read(from: &buf)
)
}
public static func write(_ value: MozAdsRequestOptions, into buf: inout [UInt8]) {
FfiConverterSequenceString.write(value.blocks, into: &buf)
FfiConverterOptionTypeMozAdsCachePolicy.write(value.cachePolicy, into: &buf)
FfiConverterDictionaryStringBool.write(value.flags, into: &buf)
FfiConverterBool.write(value.ohttp, into: &buf)
FfiConverterDictionaryStringDouble.write(value.relevance, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsRequestOptions_lift(_ buf: RustBuffer) throws -> MozAdsRequestOptions {
return try FfiConverterTypeMozAdsRequestOptions.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsRequestOptions_lower(_ value: MozAdsRequestOptions) -> RustBuffer {
return FfiConverterTypeMozAdsRequestOptions.lower(value)
}
/**
* A sponsored content (spoc) ad returned by MARS.
*/
public struct MozAdsSpoc: Equatable, Hashable {
public var blockKey: String
public var callbacks: MozAdsCallbacks
public var caps: MozAdsSpocFrequencyCaps
public var domain: String
public var excerpt: String
public var format: String
public var imageUrl: AdsClientUrl
public var ranking: MozAdsSpocRanking
public var sponsor: String
public var sponsoredByOverride: String?
public var title: String
public var url: AdsClientUrl
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(blockKey: String, callbacks: MozAdsCallbacks, caps: MozAdsSpocFrequencyCaps, domain: String, excerpt: String, format: String, imageUrl: AdsClientUrl, ranking: MozAdsSpocRanking, sponsor: String, sponsoredByOverride: String?, title: String, url: AdsClientUrl) {
self.blockKey = blockKey
self.callbacks = callbacks
self.caps = caps
self.domain = domain
self.excerpt = excerpt
self.format = format
self.imageUrl = imageUrl
self.ranking = ranking
self.sponsor = sponsor
self.sponsoredByOverride = sponsoredByOverride
self.title = title
self.url = url
}
}
#if compiler(>=6)
extension MozAdsSpoc: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsSpoc: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsSpoc {
return
try MozAdsSpoc(
blockKey: FfiConverterString.read(from: &buf),
callbacks: FfiConverterTypeMozAdsCallbacks.read(from: &buf),
caps: FfiConverterTypeMozAdsSpocFrequencyCaps.read(from: &buf),
domain: FfiConverterString.read(from: &buf),
excerpt: FfiConverterString.read(from: &buf),
format: FfiConverterString.read(from: &buf),
imageUrl: FfiConverterTypeAdsClientUrl.read(from: &buf),
ranking: FfiConverterTypeMozAdsSpocRanking.read(from: &buf),
sponsor: FfiConverterString.read(from: &buf),
sponsoredByOverride: FfiConverterOptionString.read(from: &buf),
title: FfiConverterString.read(from: &buf),
url: FfiConverterTypeAdsClientUrl.read(from: &buf)
)
}
public static func write(_ value: MozAdsSpoc, into buf: inout [UInt8]) {
FfiConverterString.write(value.blockKey, into: &buf)
FfiConverterTypeMozAdsCallbacks.write(value.callbacks, into: &buf)
FfiConverterTypeMozAdsSpocFrequencyCaps.write(value.caps, into: &buf)
FfiConverterString.write(value.domain, into: &buf)
FfiConverterString.write(value.excerpt, into: &buf)
FfiConverterString.write(value.format, into: &buf)
FfiConverterTypeAdsClientUrl.write(value.imageUrl, into: &buf)
FfiConverterTypeMozAdsSpocRanking.write(value.ranking, into: &buf)
FfiConverterString.write(value.sponsor, into: &buf)
FfiConverterOptionString.write(value.sponsoredByOverride, into: &buf)
FfiConverterString.write(value.title, into: &buf)
FfiConverterTypeAdsClientUrl.write(value.url, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsSpoc_lift(_ buf: RustBuffer) throws -> MozAdsSpoc {
return try FfiConverterTypeMozAdsSpoc.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsSpoc_lower(_ value: MozAdsSpoc) -> RustBuffer {
return FfiConverterTypeMozAdsSpoc.lower(value)
}
/**
* Frequency capping information for a spoc.
*/
public struct MozAdsSpocFrequencyCaps: Equatable, Hashable {
public var capKey: String
public var day: UInt32
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(capKey: String, day: UInt32) {
self.capKey = capKey
self.day = day
}
}
#if compiler(>=6)
extension MozAdsSpocFrequencyCaps: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsSpocFrequencyCaps: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsSpocFrequencyCaps {
return
try MozAdsSpocFrequencyCaps(
capKey: FfiConverterString.read(from: &buf),
day: FfiConverterUInt32.read(from: &buf)
)
}
public static func write(_ value: MozAdsSpocFrequencyCaps, into buf: inout [UInt8]) {
FfiConverterString.write(value.capKey, into: &buf)
FfiConverterUInt32.write(value.day, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsSpocFrequencyCaps_lift(_ buf: RustBuffer) throws -> MozAdsSpocFrequencyCaps {
return try FfiConverterTypeMozAdsSpocFrequencyCaps.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsSpocFrequencyCaps_lower(_ value: MozAdsSpocFrequencyCaps) -> RustBuffer {
return FfiConverterTypeMozAdsSpocFrequencyCaps.lower(value)
}
/**
* Ranking and personalization information for a spoc.
*/
public struct MozAdsSpocRanking: Equatable, Hashable {
public var itemScore: Double
public var personalizationModels: [String: UInt32]
public var priority: UInt32
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(itemScore: Double, personalizationModels: [String: UInt32], priority: UInt32) {
self.itemScore = itemScore
self.personalizationModels = personalizationModels
self.priority = priority
}
}
#if compiler(>=6)
extension MozAdsSpocRanking: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsSpocRanking: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsSpocRanking {
return
try MozAdsSpocRanking(
itemScore: FfiConverterDouble.read(from: &buf),
personalizationModels: FfiConverterDictionaryStringUInt32.read(from: &buf),
priority: FfiConverterUInt32.read(from: &buf)
)
}
public static func write(_ value: MozAdsSpocRanking, into buf: inout [UInt8]) {
FfiConverterDouble.write(value.itemScore, into: &buf)
FfiConverterDictionaryStringUInt32.write(value.personalizationModels, into: &buf)
FfiConverterUInt32.write(value.priority, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsSpocRanking_lift(_ buf: RustBuffer) throws -> MozAdsSpocRanking {
return try FfiConverterTypeMozAdsSpocRanking.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsSpocRanking_lower(_ value: MozAdsSpocRanking) -> RustBuffer {
return FfiConverterTypeMozAdsSpocRanking.lower(value)
}
/**
* The SQLite database the stateful client keeps its ads in.
*/
public struct MozAdsStoreConfig: Equatable, Hashable {
public var dbPath: String
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(dbPath: String) {
self.dbPath = dbPath
}
}
#if compiler(>=6)
extension MozAdsStoreConfig: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsStoreConfig: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsStoreConfig {
return
try MozAdsStoreConfig(
dbPath: FfiConverterString.read(from: &buf)
)
}
public static func write(_ value: MozAdsStoreConfig, into buf: inout [UInt8]) {
FfiConverterString.write(value.dbPath, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsStoreConfig_lift(_ buf: RustBuffer) throws -> MozAdsStoreConfig {
return try FfiConverterTypeMozAdsStoreConfig.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsStoreConfig_lower(_ value: MozAdsStoreConfig) -> RustBuffer {
return FfiConverterTypeMozAdsStoreConfig.lower(value)
}
/**
* A tile ad returned by MARS.
*/
public struct MozAdsTile: Equatable, Hashable {
public var blockKey: String
public var callbacks: MozAdsCallbacks
public var format: String
public var imageUrl: AdsClientUrl
public var name: String
public var url: AdsClientUrl
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(blockKey: String, callbacks: MozAdsCallbacks, format: String, imageUrl: AdsClientUrl, name: String, url: AdsClientUrl) {
self.blockKey = blockKey
self.callbacks = callbacks
self.format = format
self.imageUrl = imageUrl
self.name = name
self.url = url
}
}
#if compiler(>=6)
extension MozAdsTile: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsTile: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsTile {
return
try MozAdsTile(
blockKey: FfiConverterString.read(from: &buf),
callbacks: FfiConverterTypeMozAdsCallbacks.read(from: &buf),
format: FfiConverterString.read(from: &buf),
imageUrl: FfiConverterTypeAdsClientUrl.read(from: &buf),
name: FfiConverterString.read(from: &buf),
url: FfiConverterTypeAdsClientUrl.read(from: &buf)
)
}
public static func write(_ value: MozAdsTile, into buf: inout [UInt8]) {
FfiConverterString.write(value.blockKey, into: &buf)
FfiConverterTypeMozAdsCallbacks.write(value.callbacks, into: &buf)
FfiConverterString.write(value.format, into: &buf)
FfiConverterTypeAdsClientUrl.write(value.imageUrl, into: &buf)
FfiConverterString.write(value.name, into: &buf)
FfiConverterTypeAdsClientUrl.write(value.url, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsTile_lift(_ buf: RustBuffer) throws -> MozAdsTile {
return try FfiConverterTypeMozAdsTile.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsTile_lower(_ value: MozAdsTile) -> RustBuffer {
return FfiConverterTypeMozAdsTile.lower(value)
}
/**
* Whether a request reads the cache before the network.
*/
public enum MozAdsCacheMode: Equatable, Hashable {
case cacheFirst
case networkFirst
}
#if compiler(>=6)
extension MozAdsCacheMode: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsCacheMode: FfiConverterRustBuffer {
typealias SwiftType = MozAdsCacheMode
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsCacheMode {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .cacheFirst
case 2: return .networkFirst
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: MozAdsCacheMode, into buf: inout [UInt8]) {
switch value {
case .cacheFirst:
writeInt(&buf, Int32(1))
case .networkFirst:
writeInt(&buf, Int32(2))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCacheMode_lift(_ buf: RustBuffer) throws -> MozAdsCacheMode {
return try FfiConverterTypeMozAdsCacheMode.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsCacheMode_lower(_ value: MozAdsCacheMode) -> RustBuffer {
return FfiConverterTypeMozAdsCacheMode.lower(value)
}
/**
* The error every ads client method can throw.
*/
public
enum MozAdsClientApiError: Swift.Error, Equatable, Hashable, Foundation.LocalizedError {
case Other(reason: String
)
public var errorDescription: String? {
String(reflecting: self)
}
}
#if compiler(>=6)
extension MozAdsClientApiError: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsClientApiError: FfiConverterRustBuffer {
typealias SwiftType = MozAdsClientApiError
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsClientApiError {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .Other(
reason: try FfiConverterString.read(from: &buf)
)
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: MozAdsClientApiError, into buf: inout [UInt8]) {
switch value {
case let .Other(reason):
writeInt(&buf, Int32(1))
FfiConverterString.write(reason, into: &buf)
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClientApiError_lift(_ buf: RustBuffer) throws -> MozAdsClientApiError {
return try FfiConverterTypeMozAdsClientApiError.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsClientApiError_lower(_ value: MozAdsClientApiError) -> RustBuffer {
return FfiConverterTypeMozAdsClientApiError.lower(value)
}
/**
* The MARS environment the client sends requests to. Defaults to `Prod`.
*
* Variants are deliberately unsorted: UniFFI encodes them by index, and
* this mirrors `Environment`.
*/
public enum MozAdsEnvironment: Equatable, Hashable {
case prod
case staging
case custom(AdsClientUrl
)
}
#if compiler(>=6)
extension MozAdsEnvironment: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsEnvironment: FfiConverterRustBuffer {
typealias SwiftType = MozAdsEnvironment
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsEnvironment {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .prod
case 2: return .staging
case 3: return .custom(try FfiConverterTypeAdsClientUrl.read(from: &buf)
)
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: MozAdsEnvironment, into buf: inout [UInt8]) {
switch value {
case .prod:
writeInt(&buf, Int32(1))
case .staging:
writeInt(&buf, Int32(2))
case let .custom(v1):
writeInt(&buf, Int32(3))
FfiConverterTypeAdsClientUrl.write(v1, into: &buf)
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsEnvironment_lift(_ buf: RustBuffer) throws -> MozAdsEnvironment {
return try FfiConverterTypeMozAdsEnvironment.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsEnvironment_lower(_ value: MozAdsEnvironment) -> RustBuffer {
return FfiConverterTypeMozAdsEnvironment.lower(value)
}
/**
* The version of the IAB Content Taxonomy that category ids refer to.
*/
public enum MozAdsIabContentTaxonomy: Equatable, Hashable {
case iab10
case iab20
case iab21
case iab22
case iab30
}
#if compiler(>=6)
extension MozAdsIabContentTaxonomy: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsIABContentTaxonomy: FfiConverterRustBuffer {
typealias SwiftType = MozAdsIabContentTaxonomy
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsIabContentTaxonomy {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .iab10
case 2: return .iab20
case 3: return .iab21
case 4: return .iab22
case 5: return .iab30
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: MozAdsIabContentTaxonomy, into buf: inout [UInt8]) {
switch value {
case .iab10:
writeInt(&buf, Int32(1))
case .iab20:
writeInt(&buf, Int32(2))
case .iab21:
writeInt(&buf, Int32(3))
case .iab22:
writeInt(&buf, Int32(4))
case .iab30:
writeInt(&buf, Int32(5))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsIABContentTaxonomy_lift(_ buf: RustBuffer) throws -> MozAdsIabContentTaxonomy {
return try FfiConverterTypeMozAdsIABContentTaxonomy.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsIABContentTaxonomy_lower(_ value: MozAdsIabContentTaxonomy) -> RustBuffer {
return FfiConverterTypeMozAdsIABContentTaxonomy.lower(value)
}
/**
* An ad from a placement that can return either an image or a spoc.
*/
public enum MozAdsImageOrSpoc: Equatable, Hashable {
case image(MozAdsImage
)
case spoc(MozAdsSpoc
)
}
#if compiler(>=6)
extension MozAdsImageOrSpoc: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsImageOrSpoc: FfiConverterRustBuffer {
typealias SwiftType = MozAdsImageOrSpoc
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsImageOrSpoc {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .image(try FfiConverterTypeMozAdsImage.read(from: &buf)
)
case 2: return .spoc(try FfiConverterTypeMozAdsSpoc.read(from: &buf)
)
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: MozAdsImageOrSpoc, into buf: inout [UInt8]) {
switch value {
case let .image(v1):
writeInt(&buf, Int32(1))
FfiConverterTypeMozAdsImage.write(v1, into: &buf)
case let .spoc(v1):
writeInt(&buf, Int32(2))
FfiConverterTypeMozAdsSpoc.write(v1, into: &buf)
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsImageOrSpoc_lift(_ buf: RustBuffer) throws -> MozAdsImageOrSpoc {
return try FfiConverterTypeMozAdsImageOrSpoc.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsImageOrSpoc_lower(_ value: MozAdsImageOrSpoc) -> RustBuffer {
return FfiConverterTypeMozAdsImageOrSpoc.lower(value)
}
/**
* Why the user reported an ad.
*/
public enum MozAdsReportReason: Equatable, Hashable {
case inappropriate
case notInterested
case seenTooManyTimes
case scam
case misleading
case offensive
}
#if compiler(>=6)
extension MozAdsReportReason: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeMozAdsReportReason: FfiConverterRustBuffer {
typealias SwiftType = MozAdsReportReason
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MozAdsReportReason {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .inappropriate
case 2: return .notInterested
case 3: return .seenTooManyTimes
case 4: return .scam
case 5: return .misleading
case 6: return .offensive
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: MozAdsReportReason, into buf: inout [UInt8]) {
switch value {
case .inappropriate:
writeInt(&buf, Int32(1))
case .notInterested:
writeInt(&buf, Int32(2))
case .seenTooManyTimes:
writeInt(&buf, Int32(3))
case .scam:
writeInt(&buf, Int32(4))
case .misleading:
writeInt(&buf, Int32(5))
case .offensive:
writeInt(&buf, Int32(6))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsReportReason_lift(_ buf: RustBuffer) throws -> MozAdsReportReason {
return try FfiConverterTypeMozAdsReportReason.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeMozAdsReportReason_lower(_ value: MozAdsReportReason) -> RustBuffer {
return FfiConverterTypeMozAdsReportReason.lower(value)
}
/**
* Receives the ads client's metrics, for the app to record in Glean.
*/
public protocol MozAdsTelemetry: AnyObject, Sendable {
/**
* The HTTP cache could not be built (`ads_client.build_cache_error`).
*/
func recordBuildCacheError(label: String, value: String)
/**
* A client operation failed (`ads_client.client_error`).
*/
func recordClientError(label: String, value: String)
/**
* A client operation was attempted (`ads_client.client_operation_total`).
*/
func recordClientOperationTotal(label: String)
/**
* An ad in a MARS response could not be parsed and was skipped
* (`ads_client.deserialization_error`).
*/
func recordDeserializationError(label: String, value: String)
/**
* The outcome of a read from the HTTP cache (`ads_client.http_cache_outcome`).
*/
func recordHttpCacheOutcome(label: String, value: String)
}
// Put the implementation in a struct so we don't pollute the top-level namespace
fileprivate struct UniffiCallbackInterfaceMozAdsTelemetry {
// Create the VTable using a series of closures.
// Swift automatically converts these into C callback functions.
//
// Store the vtable directly.
static let vtable: UniffiVTableCallbackInterfaceMozAdsTelemetry = UniffiVTableCallbackInterfaceMozAdsTelemetry(
uniffiFree: { (uniffiHandle: UInt64) -> () in
do {
try FfiConverterCallbackInterfaceMozAdsTelemetry.handleMap.remove(handle: uniffiHandle)
} catch {
print("Uniffi callback interface MozAdsTelemetry: handle missing in uniffiFree")
}
},
uniffiClone: { (uniffiHandle: UInt64) -> UInt64 in
do {
return try FfiConverterCallbackInterfaceMozAdsTelemetry.handleMap.clone(handle: uniffiHandle)
} catch {
fatalError("Uniffi callback interface MozAdsTelemetry: handle missing in uniffiClone")
}
},
recordBuildCacheError: { (
uniffiHandle: UInt64,
label: RustBuffer,
value: RustBuffer,
uniffiOutReturn: UnsafeMutableRawPointer,
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
) in
let makeCall = {
() throws -> () in
guard let uniffiObj = try? FfiConverterCallbackInterfaceMozAdsTelemetry.handleMap.get(handle: uniffiHandle) else {
throw UniffiInternalError.unexpectedStaleHandle
}
return uniffiObj.recordBuildCacheError(
label: try FfiConverterString.lift(label),
value: try FfiConverterString.lift(value)
)
}
let writeReturn = { () }
uniffiTraitInterfaceCall(
callStatus: uniffiCallStatus,
makeCall: makeCall,
writeReturn: writeReturn
)
},
recordClientError: { (
uniffiHandle: UInt64,
label: RustBuffer,
value: RustBuffer,
uniffiOutReturn: UnsafeMutableRawPointer,
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
) in
let makeCall = {
() throws -> () in
guard let uniffiObj = try? FfiConverterCallbackInterfaceMozAdsTelemetry.handleMap.get(handle: uniffiHandle) else {
throw UniffiInternalError.unexpectedStaleHandle
}
return uniffiObj.recordClientError(
label: try FfiConverterString.lift(label),
value: try FfiConverterString.lift(value)
)
}
let writeReturn = { () }
uniffiTraitInterfaceCall(
callStatus: uniffiCallStatus,
makeCall: makeCall,
writeReturn: writeReturn
)
},
recordClientOperationTotal: { (
uniffiHandle: UInt64,
label: RustBuffer,
uniffiOutReturn: UnsafeMutableRawPointer,
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
) in
let makeCall = {
() throws -> () in
guard let uniffiObj = try? FfiConverterCallbackInterfaceMozAdsTelemetry.handleMap.get(handle: uniffiHandle) else {
throw UniffiInternalError.unexpectedStaleHandle
}
return uniffiObj.recordClientOperationTotal(
label: try FfiConverterString.lift(label)
)
}
let writeReturn = { () }
uniffiTraitInterfaceCall(
callStatus: uniffiCallStatus,
makeCall: makeCall,
writeReturn: writeReturn
)
},
recordDeserializationError: { (
uniffiHandle: UInt64,
label: RustBuffer,
value: RustBuffer,
uniffiOutReturn: UnsafeMutableRawPointer,
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
) in
let makeCall = {
() throws -> () in
guard let uniffiObj = try? FfiConverterCallbackInterfaceMozAdsTelemetry.handleMap.get(handle: uniffiHandle) else {
throw UniffiInternalError.unexpectedStaleHandle
}
return uniffiObj.recordDeserializationError(
label: try FfiConverterString.lift(label),
value: try FfiConverterString.lift(value)
)
}
let writeReturn = { () }
uniffiTraitInterfaceCall(
callStatus: uniffiCallStatus,
makeCall: makeCall,
writeReturn: writeReturn
)
},
recordHttpCacheOutcome: { (
uniffiHandle: UInt64,
label: RustBuffer,
value: RustBuffer,
uniffiOutReturn: UnsafeMutableRawPointer,
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
) in
let makeCall = {
() throws -> () in
guard let uniffiObj = try? FfiConverterCallbackInterfaceMozAdsTelemetry.handleMap.get(handle: uniffiHandle) else {
throw UniffiInternalError.unexpectedStaleHandle
}
return uniffiObj.recordHttpCacheOutcome(
label: try FfiConverterString.lift(label),
value: try FfiConverterString.lift(value)
)
}
let writeReturn = { () }
uniffiTraitInterfaceCall(
callStatus: uniffiCallStatus,
makeCall: makeCall,
writeReturn: writeReturn
)
}
)
// Rust stores this pointer for future callback invocations, so it must live
// for the process lifetime (not just for the init function call).
//
// `nonisolated(unsafe)` is needed under Swift 6 strict concurrency.
// This is safe because the pointee is initialized once during static init
// and never mutated by either side of the FFI. Its fields are C function pointers.
nonisolated(unsafe) static let vtablePtr: UnsafePointer<UniffiVTableCallbackInterfaceMozAdsTelemetry> = {
let ptr = UnsafeMutablePointer<UniffiVTableCallbackInterfaceMozAdsTelemetry>.allocate(capacity: 1)
ptr.initialize(to: vtable)
return UnsafePointer(ptr)
}()
}
private func uniffiCallbackInitMozAdsTelemetry() {
uniffi_ads_client_fn_init_callback_vtable_mozadstelemetry(UniffiCallbackInterfaceMozAdsTelemetry.vtablePtr)
}
// FfiConverter protocol for callback interfaces
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterCallbackInterfaceMozAdsTelemetry {
fileprivate static let handleMap = UniffiHandleMap<MozAdsTelemetry>()
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
extension FfiConverterCallbackInterfaceMozAdsTelemetry : FfiConverter {
typealias SwiftType = MozAdsTelemetry
typealias FfiType = UInt64
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lift(_ handle: UInt64) throws -> SwiftType {
try handleMap.get(handle: handle)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
let handle: UInt64 = try readInt(&buf)
return try lift(handle)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lower(_ v: SwiftType) -> UInt64 {
return handleMap.insert(obj: v)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
writeInt(&buf, lower(v))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterCallbackInterfaceMozAdsTelemetry_lift(_ handle: UInt64) throws -> MozAdsTelemetry {
return try FfiConverterCallbackInterfaceMozAdsTelemetry.lift(handle)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterCallbackInterfaceMozAdsTelemetry_lower(_ v: MozAdsTelemetry) -> UInt64 {
return FfiConverterCallbackInterfaceMozAdsTelemetry.lower(v)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer {
typealias SwiftType = UInt64?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterUInt64.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterUInt64.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
typealias SwiftType = String?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterString.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterString.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeMozAdsCachePolicy: FfiConverterRustBuffer {
typealias SwiftType = MozAdsCachePolicy?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeMozAdsCachePolicy.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeMozAdsCachePolicy.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeMozAdsCallbackOptions: FfiConverterRustBuffer {
typealias SwiftType = MozAdsCallbackOptions?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeMozAdsCallbackOptions.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeMozAdsCallbackOptions.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeMozAdsIABContent: FfiConverterRustBuffer {
typealias SwiftType = MozAdsIabContent?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeMozAdsIABContent.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeMozAdsIABContent.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeMozAdsRequestOptions: FfiConverterRustBuffer {
typealias SwiftType = MozAdsRequestOptions?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeMozAdsRequestOptions.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeMozAdsRequestOptions.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeAdsClientUrl: FfiConverterRustBuffer {
typealias SwiftType = AdsClientUrl?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeAdsClientUrl.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeAdsClientUrl.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
typealias SwiftType = [String]
public static func write(_ value: [String], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterString.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] {
let len: Int32 = try readInt(&buf)
var seq = [String]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterString.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeMozAdsPlacementRequest: FfiConverterRustBuffer {
typealias SwiftType = [MozAdsPlacementRequest]
public static func write(_ value: [MozAdsPlacementRequest], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeMozAdsPlacementRequest.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MozAdsPlacementRequest] {
let len: Int32 = try readInt(&buf)
var seq = [MozAdsPlacementRequest]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeMozAdsPlacementRequest.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeMozAdsPlacementRequestWithCount: FfiConverterRustBuffer {
typealias SwiftType = [MozAdsPlacementRequestWithCount]
public static func write(_ value: [MozAdsPlacementRequestWithCount], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeMozAdsPlacementRequestWithCount.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MozAdsPlacementRequestWithCount] {
let len: Int32 = try readInt(&buf)
var seq = [MozAdsPlacementRequestWithCount]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeMozAdsPlacementRequestWithCount.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeMozAdsSpoc: FfiConverterRustBuffer {
typealias SwiftType = [MozAdsSpoc]
public static func write(_ value: [MozAdsSpoc], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeMozAdsSpoc.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MozAdsSpoc] {
let len: Int32 = try readInt(&buf)
var seq = [MozAdsSpoc]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeMozAdsSpoc.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeMozAdsImageOrSpoc: FfiConverterRustBuffer {
typealias SwiftType = [MozAdsImageOrSpoc]
public static func write(_ value: [MozAdsImageOrSpoc], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeMozAdsImageOrSpoc.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MozAdsImageOrSpoc] {
let len: Int32 = try readInt(&buf)
var seq = [MozAdsImageOrSpoc]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeMozAdsImageOrSpoc.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringUInt32: FfiConverterRustBuffer {
public static func write(_ value: [String: UInt32], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterUInt32.write(value, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: UInt32] {
let len: Int32 = try readInt(&buf)
var dict = [String: UInt32]()
dict.reserveCapacity(Int(len))
for _ in 0..<len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterUInt32.read(from: &buf)
dict[key] = value
}
return dict
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringDouble: FfiConverterRustBuffer {
public static func write(_ value: [String: Double], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterDouble.write(value, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: Double] {
let len: Int32 = try readInt(&buf)
var dict = [String: Double]()
dict.reserveCapacity(Int(len))
for _ in 0..<len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterDouble.read(from: &buf)
dict[key] = value
}
return dict
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringBool: FfiConverterRustBuffer {
public static func write(_ value: [String: Bool], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterBool.write(value, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: Bool] {
let len: Int32 = try readInt(&buf)
var dict = [String: Bool]()
dict.reserveCapacity(Int(len))
for _ in 0..<len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterBool.read(from: &buf)
dict[key] = value
}
return dict
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringTypeMozAdsImage: FfiConverterRustBuffer {
public static func write(_ value: [String: MozAdsImage], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterTypeMozAdsImage.write(value, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: MozAdsImage] {
let len: Int32 = try readInt(&buf)
var dict = [String: MozAdsImage]()
dict.reserveCapacity(Int(len))
for _ in 0..<len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterTypeMozAdsImage.read(from: &buf)
dict[key] = value
}
return dict
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringTypeMozAdsTile: FfiConverterRustBuffer {
public static func write(_ value: [String: MozAdsTile], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterTypeMozAdsTile.write(value, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: MozAdsTile] {
let len: Int32 = try readInt(&buf)
var dict = [String: MozAdsTile]()
dict.reserveCapacity(Int(len))
for _ in 0..<len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterTypeMozAdsTile.read(from: &buf)
dict[key] = value
}
return dict
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringSequenceTypeMozAdsSpoc: FfiConverterRustBuffer {
public static func write(_ value: [String: [MozAdsSpoc]], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterSequenceTypeMozAdsSpoc.write(value, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: [MozAdsSpoc]] {
let len: Int32 = try readInt(&buf)
var dict = [String: [MozAdsSpoc]]()
dict.reserveCapacity(Int(len))
for _ in 0..<len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterSequenceTypeMozAdsSpoc.read(from: &buf)
dict[key] = value
}
return dict
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterDictionaryStringSequenceTypeMozAdsImageOrSpoc: FfiConverterRustBuffer {
public static func write(_ value: [String: [MozAdsImageOrSpoc]], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterString.write(key, into: &buf)
FfiConverterSequenceTypeMozAdsImageOrSpoc.write(value, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: [MozAdsImageOrSpoc]] {
let len: Int32 = try readInt(&buf)
var dict = [String: [MozAdsImageOrSpoc]]()
dict.reserveCapacity(Int(len))
for _ in 0..<len {
let key = try FfiConverterString.read(from: &buf)
let value = try FfiConverterSequenceTypeMozAdsImageOrSpoc.read(from: &buf)
dict[key] = value
}
return dict
}
}
public typealias AdsClientUrl = String
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeAdsClientUrl: FfiConverter {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AdsClientUrl {
return try FfiConverterString.read(from: &buf)
}
public static func write(_ value: AdsClientUrl, into buf: inout [UInt8]) {
return FfiConverterString.write(value, into: &buf)
}
public static func lift(_ value: RustBuffer) throws -> AdsClientUrl {
return try FfiConverterString.lift(value)
}
public static func lower(_ value: AdsClientUrl) -> RustBuffer {
return FfiConverterString.lower(value)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAdsClientUrl_lift(_ value: RustBuffer) throws -> AdsClientUrl {
return try FfiConverterTypeAdsClientUrl.lift(value)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAdsClientUrl_lower(_ value: AdsClientUrl) -> RustBuffer {
return FfiConverterTypeAdsClientUrl.lower(value)
}
private enum InitializationResult {
case ok
case contractVersionMismatch
case apiChecksumMismatch
}
// Use a global variable to perform the versioning checks. Swift ensures that
// the code inside is only computed once.
private let initializationResult: InitializationResult = {
// Get the bindings contract version from our ComponentInterface
let bindings_contract_version = 30
// Get the scaffolding contract version by calling the into the dylib
let scaffolding_contract_version = ffi_ads_client_uniffi_contract_version()
if bindings_contract_version != scaffolding_contract_version {
return InitializationResult.contractVersionMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_clear_cache() != 55903) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_record_click() != 60350) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_record_impression() != 7925) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_report_ad() != 26035) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_request_image_ads() != 15065) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_request_spoc_ads() != 47117) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_request_spoc_or_image_ads() != 40144) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_request_tile_ads() != 64774) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclient_shutdown() != 44373) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclientbuilder_build() != 21245) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclientbuilder_cache_config() != 64624) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclientbuilder_environment() != 57301) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclientbuilder_telemetry() != 29539) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadsclientbuilder_user_agent() != 51123) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_constructor_mozadsclientbuilder_new() != 48831) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadstelemetry_record_build_cache_error() != 25943) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadstelemetry_record_client_error() != 61352) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadstelemetry_record_client_operation_total() != 59338) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadstelemetry_record_deserialization_error() != 64876) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_ads_client_checksum_method_mozadstelemetry_record_http_cache_outcome() != 42241) {
return InitializationResult.apiChecksumMismatch
}
uniffiCallbackInitMozAdsTelemetry()
return InitializationResult.ok
}()
// Make the ensure init function public so that other modules which have external type references to
// our types can call it.
public func uniffiEnsureAdsClientInitialized() {
switch initializationResult {
case .ok:
break
case .contractVersionMismatch:
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
case .apiChecksumMismatch:
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}
// swiftlint:enable all