Convert some public structs to immutable final classes.

This commit is contained in:
Brent Simmons 2024-09-09 21:57:54 -07:00
parent b23888a20b
commit 6d798ee167
3 changed files with 35 additions and 4 deletions

View File

@ -8,7 +8,7 @@
import Foundation
public struct ParsedAttachment: Hashable, Sendable {
public final class ParsedAttachment: Hashable, Sendable {
public let url: String
public let mimeType: String?
@ -33,4 +33,10 @@ public struct ParsedAttachment: Hashable, Sendable {
public func hash(into hasher: inout Hasher) {
hasher.combine(url)
}
// MARK: - Equatable
public static func ==(lhs: ParsedAttachment, rhs: ParsedAttachment) -> Bool {
lhs.url == rhs.url && lhs.mimeType == rhs.mimeType && lhs.title == rhs.title && lhs.sizeInBytes == rhs.sizeInBytes && lhs.durationInSeconds == rhs.durationInSeconds
}
}

View File

@ -8,7 +8,7 @@
import Foundation
public struct ParsedAuthor: Hashable, Codable, Sendable {
public final class ParsedAuthor: Hashable, Codable, Sendable {
public let name: String?
public let url: String?
@ -23,7 +23,7 @@ public struct ParsedAuthor: Hashable, Codable, Sendable {
}
/// Use when the actual property is unknown. Guess based on contents of the string. (This is common with RSS.)
init(singleString: String) {
convenience init(singleString: String) {
if singleString.contains("@") {
self.init(name: nil, url: nil, avatarURL: nil, emailAddress: singleString)
@ -53,4 +53,11 @@ public struct ParsedAuthor: Hashable, Codable, Sendable {
hasher.combine("")
}
}
// MARK: - Equatable
public static func ==(lhs: ParsedAuthor, rhs: ParsedAuthor) -> Bool {
lhs.name == rhs.name && lhs.url == rhs.url && lhs.avatarURL == rhs.avatarURL && lhs.emailAddress == rhs.emailAddress
}
}

View File

@ -8,8 +8,26 @@
import Foundation
public struct ParsedHub: Hashable, Sendable {
public final class ParsedHub: Hashable, Sendable {
public let type: String
public let url: String
init(type: String, url: String) {
self.type = type
self.url = url
}
// MARK: - Hashable
public func hash(into hasher: inout Hasher) {
hasher.combine(type)
hasher.combine(url)
}
// MARK: - Equatable
public static func ==(lhs: ParsedHub, rhs: ParsedHub) -> Bool {
lhs.type == rhs.type && lhs.url == rhs.url
}
}