0001    //
0002    //  RawRepresentable.swift
0003    //  Himotoki
0004    //
0005    //  Created by Syo Ikeda on 9/27/15.
0006    //  Copyright © 2015 Syo Ikeda. All rights reserved.
0007    //
0008    
0009    public extension RawRepresentable where Self: Decodable, Self.DecodedType == Self, RawValue: Decodable, RawValue.DecodedType == RawValue {
0010        static func decode(e: Extractor) throws -> Self {
0011            let rawValue = try RawValue.decode(e)
0012    
0013            guard let value = self.init(rawValue: rawValue) else {
0014                throw typeMismatch("rawValue for \(self)", actual: rawValue, keyPath: nil)
0015            }
0016    
0017            return value
0018        }
0019    }
0020