mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-28 05:14:27 +00:00
Resolves #634 The majority of types that were Equatable are now Hashable. Anywhere that we had a custom == and the type was also Hashable we also now have custom hash functions.
53 lines
1.6 KiB
Swift
53 lines
1.6 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2021 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// A textual RFC-2822 date.
|
|
///
|
|
/// See RFC-2822 section 3.3. “Date and Time Specification”.
|
|
///
|
|
/// Use `String(init(_: InternetMessageDate)` to get the underlying string representation.
|
|
public struct InternetMessageDate: Hashable {
|
|
var value: String
|
|
|
|
/// Creates a new `InternetMessageDate` from a given `String`.
|
|
/// - parameter string: A `String` containing some textual date value.
|
|
public init(_ string: String) {
|
|
self.value = string
|
|
}
|
|
}
|
|
|
|
extension String {
|
|
/// Creates a new `String` from an `InternetMessageDate`
|
|
/// - parameter date: The `InternetMessageDate`.
|
|
public init(_ date: InternetMessageDate) {
|
|
self = date.value
|
|
}
|
|
}
|
|
|
|
extension InternetMessageDate: ExpressibleByStringLiteral {
|
|
/// Creates a new `InternetMessageDate` from a given `String`.
|
|
/// - parameter stringLiteral: A `String` containing some textual date value.
|
|
public init(stringLiteral value: String) {
|
|
self.value = value
|
|
}
|
|
}
|
|
|
|
// MARK: - Encoding
|
|
|
|
extension EncodeBuffer {
|
|
@discardableResult mutating func writeInternetMessageDate(_ date: InternetMessageDate) -> Int {
|
|
self.writeString(date.value)
|
|
}
|
|
}
|