30 lines
814 B
Swift
30 lines
814 B
Swift
public struct Identifier<ObjectType>: RawRepresentable, Hashable, Codable, ExpressibleByStringLiteral,
|
|
CustomStringConvertible {
|
|
public var rawValue: String
|
|
public init(rawValue: String) {
|
|
self.rawValue = rawValue
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container = try decoder.singleValueContainer()
|
|
self.rawValue = try container.decode(String.self)
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.singleValueContainer()
|
|
try container.encode(rawValue)
|
|
}
|
|
|
|
public init(stringLiteral value: StringLiteralType) {
|
|
self.rawValue = value
|
|
}
|
|
|
|
public var description: String {
|
|
rawValue
|
|
}
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
hasher.combine(rawValue)
|
|
}
|
|
}
|