func checked()

in Sources/_TracingBenchmarkTools/ArgParser.swift [55:70]


func checked<T>(
    _ parse: (String) throws -> T?,
    _ value: String,
    argument: String? = nil
) throws -> T {
    if let t = try parse(value) { return t }
    var type = "\(T.self)"
    if type.starts(with: "Optional<") {
        let s = type.index(after: type.firstIndex(of: "<")!)
        let e = type.index(before: type.endIndex) // ">"
        type = String(type[s ..< e]) // strip Optional< >
    }
    throw ArgumentError.invalidType(
        value: value, type: type, argument: argument
    )
}