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.
42 lines
1.3 KiB
Swift
42 lines
1.3 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import struct NIO.ByteBuffer
|
|
|
|
/// RFC 5465 - One or more mailboxes
|
|
public struct Mailboxes: Hashable {
|
|
/// Array of at least one mailbox.
|
|
public let content: [MailboxName]
|
|
|
|
/// Creates a new `Mailboxes` - there must be at least one mail box in the set.
|
|
/// - parameter mailboxes: One or more mailboxes.
|
|
/// - returns: `nil` if `mailboxes` is empty, otherwise a new `Mailboxes`
|
|
public init?(_ mailboxes: [MailboxName]) {
|
|
guard mailboxes.count >= 1 else {
|
|
return nil
|
|
}
|
|
self.content = mailboxes
|
|
}
|
|
}
|
|
|
|
// MARK: - Encoding
|
|
|
|
extension EncodeBuffer {
|
|
@discardableResult mutating func writeMailboxes(_ mailboxes: Mailboxes) -> Int {
|
|
self.writeArray(mailboxes.content) { (mailbox, buffer) -> Int in
|
|
buffer.writeMailbox(mailbox)
|
|
}
|
|
}
|
|
}
|