diff --git a/Sources/JSONAPI/Resource/Attribute.swift b/Sources/JSONAPI/Resource/Attribute.swift index e9cd99c..40d1eec 100644 --- a/Sources/JSONAPI/Resource/Attribute.swift +++ b/Sources/JSONAPI/Resource/Attribute.swift @@ -8,6 +8,8 @@ public protocol AttributeType: Codable { } +// MARK: TransformedAttribute +/// A TransformedAttribute takes a Codable type and attempts to turn it into another type. public struct TransformedAttribute: AttributeType where Transformer.From == RawValue { private let rawValue: RawValue @@ -19,6 +21,15 @@ public struct TransformedAttribute = TransformedAttribute where RawValue == Validator.From + +// MARK: Attribute +/// An Attribute simply represents a type that can be encoded and decoded. +public typealias Attribute = TransformedAttribute> + extension TransformedAttribute where Transformer: ReversibleTransformer { public init(transformedValue: Transformer.To) throws { self.value = transformedValue @@ -43,10 +54,6 @@ extension TransformedAttribute where Transformer == IdentityTransformer = TransformedAttribute where RawValue == Validator.From - -public typealias Attribute = TransformedAttribute> - // MARK: - Codable extension TransformedAttribute { public init(from decoder: Decoder) throws {