blob: bd18d97b84c70ed401de3e9ca3047a7d7827a29d [file] [log] [blame] [edit]
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
T as<T>(Object? object) {
if (object is T) {
return object;
}
throw FormatException(
"Unexpected value '$object' in JSON. Expected a $T.",
);
}
extension MapCast on Map<Object?, Object?> {
Map<K, V> formatCast<K, V>() => <K, V>{
for (final e in entries) as<K>(e.key): as<V>(e.value),
};
}