Skip to content

Commit f00cb40

Browse files
authored
SWIFT-827: Rewrite enums with ".other" case as structs (#485)
1 parent 16dc680 commit f00cb40

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

Sources/MongoSwift/ChangeStreamOptions.swift

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
/// Describes the modes for configuring the fullDocument field of a change stream document.
2-
public enum FullDocument: RawRepresentable, Codable {
2+
public struct FullDocument: RawRepresentable, Codable {
33
/// Specifies that the `fullDocument` field of an update event will contain a copy of the entire document that
44
/// was changed from some time after the change occurred. If the document was deleted since the updated happened,
55
/// it will be nil.
6-
case updateLookup
6+
public static let updateLookup = FullDocument("updateLookup")
77
/// For an unknown value. For forwards compatibility, no error will be thrown when an unknown value is provided.
8-
case other(String)
9-
10-
public var rawValue: String {
11-
switch self {
12-
case .updateLookup:
13-
return "updateLookup"
14-
case let .other(v):
15-
return v
16-
}
8+
public static func other(_ value: String) -> FullDocument {
9+
FullDocument(value)
1710
}
1811

19-
public init?(rawValue: String) {
20-
switch rawValue {
21-
case "updateLookup":
22-
self = .updateLookup
23-
default:
24-
self = .other(rawValue)
25-
}
26-
}
12+
public var rawValue: String
13+
14+
/// Creates a `FullDocument`. Never returns nil.
15+
public init?(rawValue: String) { self.rawValue = rawValue }
16+
internal init(_ value: String) { self.rawValue = value }
2717
}
2818

2919
/// Options to use when creating a `ChangeStream`.

Sources/MongoSwiftSync/Exports.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
@_exported import struct MongoSwift.FindOneAndUpdateOptions
6464
@_exported import struct MongoSwift.FindOneOptions
6565
@_exported import struct MongoSwift.FindOptions
66-
@_exported import enum MongoSwift.FullDocument
66+
@_exported import struct MongoSwift.FullDocument
6767
@_exported import enum MongoSwift.IndexHint
6868
@_exported import struct MongoSwift.IndexModel
6969
@_exported import struct MongoSwift.IndexOptions

0 commit comments

Comments
 (0)