Files
swift-nio-imap/Sources/NIOIMAPCore/Grammar/UID/UIDValidity.swift
T
David Evans a66eeb228b Use SPI to remove underscored members (#567)
Resolves #556

We've talked quite a bit offline, and decided that for now @_spi is the way to go, as it avoids build system issues. The goal is to remove the number of underscored public types and fields.
2021-06-02 19:21:47 +01:00

55 lines
1.7 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/// The unique identifier validity value of a mailbox. Combined with a message UID to form a 64-bit identifier.
public struct UIDValidity: Hashable {
/// The underlying raw value.
let rawValue: UInt32
/// Creates a `UIDValidity` from some `BinaryInteger` after checking
/// that the given value fits within a `UInt32`.
/// - parameter source: Some `BinaryInteger`.
/// - returns: `nil` if the given value cannot fit within a `UInt32`, otherwise a new `UIDValidity`.
public init?<T>(exactly source: T) where T: BinaryInteger {
guard source > 0, let rawValue = UInt32(exactly: source) else { return nil }
self.rawValue = rawValue
}
}
// MARK: - Integer literal
extension UIDValidity: ExpressibleByIntegerLiteral {
/// Creates a `UIDValidity` from some integer literal value.
/// - parameter value: The literal value.
public init(integerLiteral value: UInt32) {
self.init(exactly: value)!
}
}
// MARK: - Binary Integer
extension BinaryInteger {
public init(_ value: UIDValidity) {
self = Self(value.rawValue)
}
}
// MARK: - Encoding
extension EncodeBuffer {
@discardableResult mutating func writeUIDValidity(_ data: UIDValidity) -> Int {
self.writeString("\(data.rawValue)")
}
}