forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwiftStruct.swift
More file actions
85 lines (68 loc) · 1.76 KB
/
SwiftStruct.swift
File metadata and controls
85 lines (68 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@JS struct DataPoint {
let x: Double
let y: Double
var label: String
var optCount: Int?
var optFlag: Bool?
@JS init(x: Double, y: Double, label: String, optCount: Int?, optFlag: Bool?)
}
@JS struct Address {
var street: String
var city: String
var zipCode: Int?
}
@JS struct Person {
var name: String
var age: Int
var address: Address
var email: String?
}
@JS class Greeter {
@JS var name: String
@JS init(name: String)
@JS func greet() -> String
}
@JS struct Session {
var id: Int
var owner: Greeter
}
@JS func roundtrip(_ session: Person) -> Person
@JS enum Precision: Float {
case rough = 0.1
case fine = 0.001
}
@JS struct Measurement {
var value: Double
var precision: Precision
var optionalPrecision: Precision?
}
@JS struct ConfigStruct {
@JS static let maxRetries: Int = 3
@JS nonisolated(unsafe) static var defaultConfig: String = "production"
@JS nonisolated(unsafe) static var timeout: Double = 30.0
@JS static var computedSetting: String { "Config: \(defaultConfig)" }
@JS static func update(_ timeout: Double) -> Double
}
@JS struct Container {
var object: JSObject
var optionalObject: JSObject?
}
@JS func roundtripContainer(_ container: Container) -> Container
@JS struct Vector2D {
var dx: Double
var dy: Double
}
extension Vector2D {
@JS func magnitude() -> Double {
return (dx * dx + dy * dy).squareRoot()
}
@JS func scaled(by factor: Double) -> Vector2D {
return Vector2D(dx: dx * factor, dy: dy * factor)
}
}
extension DataPoint {
@JS static func origin() -> DataPoint {
return DataPoint(x: 0, y: 0, label: "origin", optCount: nil, optFlag: nil)
}
@JS static var dimensions: Int { 2 }
}