Files
swift-hvac-toolbox/Sources/Routes/URLRoutingExtensions.swift

41 lines
1.0 KiB
Swift

import URLRouting
// Allow the use of a field key enum as the `name` parameter, to avoid
// stringly type name fields.
public extension Field {
@inlinable
init<Key>(
_ name: Key,
default defaultValue: Value.Output? = nil,
@ParserBuilder<Substring> _ value: () -> Value
) where Key: RawRepresentable, Key.RawValue == String {
self.init(name.rawValue, default: defaultValue, value)
}
@inlinable
init<Key, C>(
_ name: Key,
_ value: C,
default defaultValue: Value.Output? = nil,
) where Key: RawRepresentable, Key.RawValue == String,
Value == Parsers.MapConversion<Parsers.ReplaceError<Rest<Substring>>, C>
{
self.init(name.rawValue, value, default: defaultValue)
}
@inlinable
init<Key>(
_ name: Key,
default defaultValue: Value.Output? = nil
)
where
Key: RawRepresentable, Key.RawValue == String,
Value == Parsers.MapConversion<
Parsers.ReplaceError<Rest<Substring>>, Conversions.SubstringToString
>
{
self.init(name.rawValue, default: defaultValue)
}
}