mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
290a1febad
Немного причесал API в выражениях и разложил по папкам.
93 lines
1.9 KiB
Swift
93 lines
1.9 KiB
Swift
import Foundation
|
|
|
|
import CommonCore
|
|
import Serialization
|
|
|
|
extension Expression where T == Bool {
|
|
func toValidSerializationValue() -> ValidSerializationValue {
|
|
switch self {
|
|
case let .value(value):
|
|
return value
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Expression where T == Double {
|
|
func toValidSerializationValue() -> ValidSerializationValue {
|
|
switch self {
|
|
case let .value(value):
|
|
return value
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Expression where T == Int {
|
|
func toValidSerializationValue() -> ValidSerializationValue {
|
|
switch self {
|
|
case let .value(value):
|
|
return value
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Expression where T == Color {
|
|
func toValidSerializationValue() -> String {
|
|
switch self {
|
|
case let .value(value):
|
|
return value.hexString
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Expression where T == String {
|
|
func toValidSerializationValue() -> String {
|
|
switch self {
|
|
case let .value(value):
|
|
return value
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Expression where T == CFString {
|
|
func toValidSerializationValue() -> String {
|
|
switch self {
|
|
case let .value(value):
|
|
return String(value)
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Expression where T == URL {
|
|
func toValidSerializationValue() -> String {
|
|
switch self {
|
|
case let .value(value):
|
|
return value.absoluteString
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Expression where T: RawRepresentable, T.RawValue == String {
|
|
func toValidSerializationValue() -> String {
|
|
switch self {
|
|
case let .value(value):
|
|
return value.rawValue
|
|
case let .link(link):
|
|
return link.rawValue
|
|
}
|
|
}
|
|
}
|