UnpackUntilType unpacks the reflect value until it matches the given type.
(t reflect.Type)
| 212 | |
| 213 | // UnpackUntilType unpacks the reflect value until it matches the given type. |
| 214 | func (v *Value) UnpackUntilType(t reflect.Type) (*Value, error) { |
| 215 | res := v.value |
| 216 | var daselValueType = reflect.TypeFor[*Value]() |
| 217 | for { |
| 218 | if res.Type() == t { |
| 219 | return NewValue(res), nil |
| 220 | } |
| 221 | if t != daselValueType && res.Type() == daselValueType { |
| 222 | m, err := v.daselValue() |
| 223 | if err != nil { |
| 224 | return nil, fmt.Errorf("error getting dasel value: %w", err) |
| 225 | } |
| 226 | res = m.value |
| 227 | continue |
| 228 | |
| 229 | } |
| 230 | if res.Kind() == reflect.Interface || res.Kind() == reflect.Pointer && !res.IsNil() { |
| 231 | res = res.Elem() |
| 232 | continue |
| 233 | } |
| 234 | return nil, &ErrCouldNotUnpackToType{Type: t} |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // UnpackUntilAddressable unpacks the reflect value until it is addressable. |
| 239 | func (v *Value) UnpackUntilAddressable() (*Value, error) { |
no test coverage detected