Skip to content

Commit 01a848a

Browse files
authored
Mutability/Sendability cleanup for HtmlAttributes (#68)
* make HTMLAttribute values immutable, remove unnecessary explicit inits * Add missing Sendable modifiers * restore inits that are required
1 parent 446ae68 commit 01a848a

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

Sources/Elementary/HtmlAttributes.swift

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global {
7979

8080
// dir attribute
8181
public extension HTMLAttributeValue {
82-
struct Direction {
83-
var value: String
82+
struct Direction: Sendable {
83+
let value: String
8484

8585
public static var ltr: Self { .init(value: "ltr") }
8686
public static var rtl: Self { .init(value: "rtl") }
@@ -89,8 +89,8 @@ public extension HTMLAttributeValue {
8989
}
9090

9191
public extension HTMLAttributeValue {
92-
struct ContentEditable {
93-
var value: String
92+
struct ContentEditable: Sendable {
93+
let value: String
9494

9595
public static var `true`: Self { .init(value: "true") }
9696
public static var `false`: Self { .init(value: "false") }
@@ -99,8 +99,8 @@ public extension HTMLAttributeValue {
9999
}
100100

101101
public extension HTMLAttributeValue {
102-
struct Popover {
103-
var value: String
102+
struct Popover: Sendable {
103+
let value: String
104104

105105
public static var auto: Self { .init(value: "auto") }
106106
public static var hint: Self { .init(value: "hint") }
@@ -111,8 +111,8 @@ public extension HTMLAttributeValue {
111111
public extension HTMLAttributeValue {
112112
// MDN docs describe draggable as having an enumerated value, but currently
113113
// the only valid values are "true" and "false"
114-
struct Draggable {
115-
var value: String
114+
struct Draggable: Sendable {
115+
let value: String
116116

117117
public static var `true`: Self { .init(value: "true") }
118118
public static var `false`: Self { .init(value: "false") }
@@ -127,8 +127,8 @@ public extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global {
127127

128128
// role attribute
129129
public extension HTMLAttributeValue {
130-
struct Role: ExpressibleByStringLiteral, RawRepresentable {
131-
public var rawValue: String
130+
struct Role: ExpressibleByStringLiteral, RawRepresentable, Sendable {
131+
public let rawValue: String
132132

133133
public init(rawValue: String) {
134134
self.rawValue = rawValue
@@ -143,7 +143,7 @@ public extension HTMLAttributeValue {
143143
// meta tag attributes
144144
public extension HTMLAttribute where Tag == HTMLTag.meta {
145145
struct Name: Sendable, ExpressibleByStringLiteral {
146-
var value: String
146+
let value: String
147147

148148
init(value: String) {
149149
self.value = value
@@ -176,7 +176,7 @@ public extension HTMLAttribute where Tag == HTMLTag.meta {
176176
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
177177
public extension HTMLAttribute where Tag == HTMLTag.link {
178178
struct As: Sendable, ExpressibleByStringLiteral {
179-
var value: String
179+
let value: String
180180

181181
init(value: String) {
182182
self.value = value
@@ -210,11 +210,7 @@ public extension HTMLAttribute where Tag == HTMLTag.link {
210210
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
211211
public extension HTMLAttribute where Tag == HTMLTag.button {
212212
struct ButtonType: Sendable {
213-
var value: String
214-
215-
init(value: String) {
216-
self.value = value
217-
}
213+
let value: String
218214

219215
public static let submit = ButtonType(value: "submit")
220216
public static let reset = ButtonType(value: "reset")
@@ -274,8 +270,8 @@ extension HTMLTag.base: HTMLTrait.Attributes.target {}
274270
extension HTMLTag.form: HTMLTrait.Attributes.target {}
275271

276272
public extension HTMLAttributeValue {
277-
struct Target: ExpressibleByStringLiteral, RawRepresentable {
278-
public var rawValue: String
273+
struct Target: ExpressibleByStringLiteral, RawRepresentable, Sendable {
274+
public let rawValue: String
279275

280276
public init(rawValue: String) {
281277
self.rawValue = rawValue
@@ -308,7 +304,7 @@ extension HTMLTag.script: HTMLTrait.Attributes.charset {}
308304

309305
public extension HTMLAttributeValue {
310306
struct CharacterSet: ExpressibleByStringLiteral, RawRepresentable, Sendable, Equatable {
311-
public var rawValue: String
307+
public let rawValue: String
312308

313309
public init(rawValue: String) {
314310
self.rawValue = rawValue
@@ -340,7 +336,7 @@ extension HTMLTag.form: HTMLTrait.Attributes.rel {}
340336

341337
public extension HTMLAttributeValue {
342338
struct Relationship: ExpressibleByStringLiteral, RawRepresentable, Sendable, Equatable {
343-
public var rawValue: String
339+
public let rawValue: String
344340

345341
public init(rawValue: String) {
346342
self.rawValue = rawValue
@@ -409,7 +405,7 @@ extension HTMLTag.textarea: HTMLTrait.Attributes.autocomplete {}
409405

410406
public extension HTMLAttributeValue {
411407
struct AutoComplete: ExpressibleByStringLiteral, RawRepresentable, Sendable, Equatable {
412-
public var rawValue: String
408+
public let rawValue: String
413409

414410
public init(rawValue: String) {
415411
self.rawValue = rawValue
@@ -498,7 +494,7 @@ extension HTMLTag.link: HTMLTrait.Attributes.crossorigin {}
498494

499495
public extension HTMLAttributeValue {
500496
struct CrossOrigin: Sendable, Equatable {
501-
var value: String
497+
let value: String
502498

503499
public static var anonymous: Self { .init(value: "anonymous") }
504500
public static var useCredentials: Self { .init(value: "use-credentials") }
@@ -535,7 +531,7 @@ extension HTMLTag.link: HTMLTrait.Attributes.referrerpolicy {}
535531

536532
public extension HTMLAttributeValue {
537533
struct ReferrerPolicy: Sendable, Equatable {
538-
var value: String
534+
let value: String
539535

540536
public static var noReferrer: Self { .init(value: "no-referrer") }
541537
public static var noReferrerWhenDowngrade: Self { .init(value: "no-referrer-when-downgrade") }
@@ -580,7 +576,7 @@ public extension HTMLAttribute where Tag: HTMLTrait.Attributes.dimensions {
580576
// form tag attributes
581577
public extension HTMLAttribute where Tag == HTMLTag.form {
582578
struct Method: Sendable, Equatable {
583-
var value: String
579+
let value: String
584580

585581
public static var get: Self { .init(value: "get") }
586582
public static var post: Self { .init(value: "post") }
@@ -598,7 +594,7 @@ public extension HTMLAttribute where Tag == HTMLTag.form {
598594
// input tag attributes
599595
public extension HTMLAttribute where Tag == HTMLTag.input {
600596
struct InputType: Sendable, Equatable {
601-
var value: String
597+
let value: String
602598

603599
public static var button: Self { .init(value: "button") }
604600
public static var checkbox: Self { .init(value: "checkbox") }
@@ -625,11 +621,7 @@ public extension HTMLAttribute where Tag == HTMLTag.input {
625621
}
626622

627623
struct Accept: Sendable, Equatable, ExpressibleByStringLiteral {
628-
var value: String
629-
630-
init(value: String) {
631-
self.value = value
632-
}
624+
let value: String
633625

634626
public init(stringLiteral value: String) {
635627
self.value = value
@@ -675,7 +667,7 @@ public extension HTMLAttribute where Tag == HTMLTag.option {
675667
public extension HTMLAttribute where Tag == HTMLTag.script {
676668
// type
677669
struct ScriptType: Sendable, ExpressibleByStringLiteral {
678-
var value: String
670+
let value: String
679671

680672
init(value: String) {
681673
self.value = value
@@ -727,7 +719,7 @@ public extension HTMLAttribute where Tag: HTMLTrait.Attributes.placeholder {
727719
// scope attribute
728720
public extension HTMLAttribute where Tag == HTMLTag.th {
729721
struct Scope: Sendable, Equatable {
730-
var value: String
722+
let value: String
731723

732724
public static var col: Self { .init(value: "col") }
733725
public static var row: Self { .init(value: "row") }

0 commit comments

Comments
 (0)