Skip to content

Commit 2846b0a

Browse files
doc: Adds val Encodable/Zinc docs
1 parent 97f9de1 commit 2846b0a

File tree

18 files changed

+106
-27
lines changed

18 files changed

+106
-27
lines changed

Sources/Haystack/Bool.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Foundation
66
extension Bool: Val {
77
public static var valType: ValType { .Bool }
88

9+
/// Converts to Zinc formatted string.
10+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
911
public func toZinc() -> String {
1012
return self ? "T" : "F"
1113
}

Sources/Haystack/Coord.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ public struct Coord: Val {
1919
self.longitude = longitude
2020
}
2121

22+
/// Converts to Zinc formatted string.
23+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
2224
public func toZinc() -> String {
2325
return "C(\(latitude),\(longitude))"
2426
}
2527
}
2628

27-
/// See https://project-haystack.org/doc/docHaystack/Json#coord
2829
extension Coord: Codable {
2930
static let kindValue = "coord"
3031

@@ -34,6 +35,8 @@ extension Coord: Codable {
3435
case lng
3536
}
3637

38+
/// Read from decodable data
39+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#coord)
3740
public init(from decoder: Decoder) throws {
3841
if let container = try? decoder.container(keyedBy: Self.CodingKeys) {
3942
guard try container.decode(String.self, forKey: ._kind) == Self.kindValue else {
@@ -61,6 +64,8 @@ extension Coord: Codable {
6164
}
6265
}
6366

67+
/// Write to encodable data
68+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#coord)
6469
public func encode(to encoder: Encoder) throws {
6570
var container = encoder.container(keyedBy: Self.CodingKeys)
6671
try container.encode(Self.kindValue, forKey: ._kind)

Sources/Haystack/Date.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public struct Date: Val {
4747
)
4848
}
4949

50+
/// Converts to Zinc formatted string.
51+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
5052
public func toZinc() -> String {
5153
return isoString
5254
}
@@ -66,7 +68,6 @@ var dateFormatter: ISO8601DateFormatter {
6668
return formatter
6769
}
6870

69-
/// See https://project-haystack.org/doc/docHaystack/Json#date
7071
extension Date {
7172
static let kindValue = "date"
7273

@@ -75,6 +76,8 @@ extension Date {
7576
case val
7677
}
7778

79+
/// Read from decodable data
80+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#date)
7881
public init(from decoder: Decoder) throws {
7982
if let container = try? decoder.container(keyedBy: Self.CodingKeys) {
8083
guard try container.decode(String.self, forKey: ._kind) == Self.kindValue else {
@@ -110,6 +113,8 @@ extension Date {
110113
}
111114
}
112115

116+
/// Write to encodable data
117+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#date)
113118
public func encode(to encoder: Encoder) throws {
114119
var container = encoder.container(keyedBy: Self.CodingKeys)
115120
try container.encode(Self.kindValue, forKey: ._kind)

Sources/Haystack/DateTime.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public struct DateTime: Val {
8989
}
9090
}
9191

92+
/// Converts to Zinc formatted string.
93+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
9294
public func toZinc() -> String {
9395
var zinc: String
9496
if hasMilliseconds {
@@ -166,14 +168,6 @@ public struct DateTime: Val {
166168
}
167169

168170
return (date, gmtOffset)
169-
170-
// if let date = dateTimeFormatter.date(from: isoString) {
171-
// return date
172-
// } else if let date = dateTimeWithMillisFormatter.date(from: isoString) {
173-
// return date
174-
// } else {
175-
// throw ValError.invalidDateTimeFormat(isoString)
176-
// }
177171
}
178172

179173
private var hasMilliseconds: Bool {
@@ -199,7 +193,6 @@ public struct DateTime: Val {
199193

200194
var calendar = Calendar(identifier: .gregorian)
201195

202-
/// See https://project-haystack.org/doc/docHaystack/Json#dateTime
203196
extension DateTime {
204197
static let kindValue = "dateTime"
205198

@@ -209,6 +202,8 @@ extension DateTime {
209202
case tz
210203
}
211204

205+
/// Read from decodable data
206+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#dateTime)
212207
public init(from decoder: Decoder) throws {
213208
guard let container = try? decoder.container(keyedBy: Self.CodingKeys) else {
214209
throw DecodingError.typeMismatch(
@@ -249,6 +244,8 @@ extension DateTime {
249244
self.timezone = timezone
250245
}
251246

247+
/// Write to encodable data
248+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#dateTime)
252249
public func encode(to encoder: Encoder) throws {
253250
var container = encoder.container(keyedBy: Self.CodingKeys)
254251
try container.encode(Self.kindValue, forKey: ._kind)

Sources/Haystack/Dict.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public struct Dict: Val {
2020
self.elements = elements
2121
}
2222

23+
/// Converts to Zinc formatted string.
24+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
2325
public func toZinc() -> String {
2426
return toZinc(withBraces: true)
2527
}
@@ -38,10 +40,11 @@ public struct Dict: Val {
3840
}
3941
}
4042

41-
/// See https://project-haystack.org/doc/docHaystack/Json#dict
4243
extension Dict {
4344
static let kindValue = "dateTime"
4445

46+
/// Read from decodable data
47+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#dict)
4548
public init(from decoder: Decoder) throws {
4649
guard let container = try? decoder.container(keyedBy: DictCodingKey.self) else {
4750
throw DecodingError.typeMismatch(
@@ -79,7 +82,9 @@ extension Dict {
7982
}
8083
self.elements = elements
8184
}
82-
85+
86+
/// Write to encodable data
87+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#dict)
8388
public func encode(to encoder: Encoder) throws {
8489
var container = encoder.container(keyedBy: DictCodingKey.self)
8590
for (key, value) in elements {

Sources/Haystack/Grid.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public struct Grid: Val {
1919
self.rows = rows
2020
}
2121

22+
/// Converts to Zinc formatted string.
23+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
2224
public func toZinc() -> String {
2325
var zinc = #"ver:"3.0""#
2426
if meta.elements.count > 0 {
@@ -49,7 +51,6 @@ public struct Grid: Val {
4951
}
5052
}
5153

52-
/// See https://project-haystack.org/doc/docHaystack/Json#grid
5354
extension Grid {
5455
static let kindValue = "grid"
5556

@@ -60,6 +61,8 @@ extension Grid {
6061
case rows
6162
}
6263

64+
/// Read from decodable data
65+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#grid)
6366
public init(from decoder: Decoder) throws {
6467
if let container = try? decoder.container(keyedBy: Self.CodingKeys) {
6568
guard try container.decode(String.self, forKey: ._kind) == Self.kindValue else {
@@ -86,6 +89,8 @@ extension Grid {
8689
}
8790
}
8891

92+
/// Write to encodable data
93+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#grid)
8994
public func encode(to encoder: Encoder) throws {
9095
var container = encoder.container(keyedBy: Self.CodingKeys)
9196
try container.encode(Self.kindValue, forKey: ._kind)

Sources/Haystack/List.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ public struct List: Val {
1313
self.elements = elements
1414
}
1515

16+
/// Converts to Zinc formatted string.
17+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
1618
public func toZinc() -> String {
1719
let zincElements = elements.map { $0.toZinc() }
1820
return "[\(zincElements.joined(separator:", "))]"
1921
}
2022
}
2123

22-
/// See https://project-haystack.org/doc/docHaystack/Json#list
23-
extension List: Encodable {
24+
extension List {
25+
26+
/// Read from decodable data
27+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#list)
2428
public init(from decoder: Decoder) throws {
2529
guard var container = try? decoder.unkeyedContainer() else {
2630
throw DecodingError.typeMismatch(
@@ -43,7 +47,9 @@ extension List: Encodable {
4347
}
4448
self.elements = elements
4549
}
46-
50+
51+
/// Write to encodable data
52+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#list)
4753
public func encode(to encoder: Encoder) throws {
4854
var container = encoder.unkeyedContainer()
4955
for element in elements {

Sources/Haystack/Marker.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@ public let marker = Marker()
1010
public struct Marker: Val {
1111
public static var valType: ValType { .Marker }
1212

13+
/// Singleton `Marker` instance
1314
public static var val: Self {
1415
return marker
1516
}
1617

18+
/// Converts to Zinc formatted string.
19+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
1720
public func toZinc() -> String {
1821
return "M"
1922
}
2023
}
2124

22-
/// See https://project-haystack.org/doc/docHaystack/Json#marker
2325
extension Marker {
2426
static let kindValue = "marker"
2527

2628
enum CodingKeys: CodingKey {
2729
case _kind
2830
}
2931

32+
/// Read from decodable data
33+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#marker)
3034
public init(from decoder: Decoder) throws {
3135
if let container = try? decoder.container(keyedBy: Self.CodingKeys) {
3236
guard try container.decode(String.self, forKey: ._kind) == Self.kindValue else {
@@ -50,6 +54,8 @@ extension Marker {
5054
}
5155
}
5256

57+
/// Write to encodable data
58+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#marker)
5359
public func encode(to encoder: Encoder) throws {
5460
var container = encoder.container(keyedBy: Self.CodingKeys)
5561
try container.encode(Self.kindValue, forKey: ._kind)

Sources/Haystack/NA.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ public struct NA: Val {
1515
return na
1616
}
1717

18+
/// Converts to Zinc formatted string.
19+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
1820
public func toZinc() -> String {
1921
return "NA"
2022
}
2123
}
2224

23-
/// See https://project-haystack.org/doc/docHaystack/Json#na
2425
extension NA {
2526
static let kindValue = "na"
2627

2728
enum CodingKeys: CodingKey {
2829
case _kind
2930
}
3031

32+
/// Read from decodable data
33+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#na)
3134
public init(from decoder: Decoder) throws {
3235
if let container = try? decoder.container(keyedBy: Self.CodingKeys) {
3336
guard try container.decode(String.self, forKey: ._kind) == Self.kindValue else {
@@ -51,6 +54,8 @@ extension NA {
5154
}
5255
}
5356

57+
/// Write to encodable data
58+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#na)
5459
public func encode(to encoder: Encoder) throws {
5560
var container = encoder.container(keyedBy: Self.CodingKeys)
5661
try container.encode(Self.kindValue, forKey: ._kind)

Sources/Haystack/Null.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ public struct Null: Val {
1313
return null
1414
}
1515

16+
/// Converts to Zinc formatted string.
17+
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
1618
public func toZinc() -> String {
1719
return "N"
1820
}
1921
}
2022

21-
/// See https://project-haystack.org/doc/docHaystack/Json#v4
2223
extension Null {
24+
25+
/// Read from decodable data
26+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#v4)
2327
public init(from decoder: Decoder) throws {
2428
if let container = try? decoder.singleValueContainer() {
2529
guard container.decodeNil() else {
@@ -43,6 +47,8 @@ extension Null {
4347
}
4448
}
4549

50+
/// Write to encodable data
51+
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#v4)
4652
public func encode(to encoder: Encoder) throws {
4753
var container = encoder.singleValueContainer()
4854
try container.encodeNil()

0 commit comments

Comments
 (0)