21
0
Fork 0
This commit is contained in:
Tim Waldmann 2023-03-21 16:00:15 +01:00
parent a6252f0743
commit 007c44df85
1 changed files with 9 additions and 0 deletions

View File

@ -60,3 +60,12 @@ func CoalesceStringer(s fmt.Stringer, def string) string {
return s.String()
}
}
func SafeCast[T any](v any, def T) T {
switch r := v.(type) {
case T:
return r
default:
return def
}
}