@@ -342,6 +342,9 @@ type rawType struct {
342
342
}
343
343
344
344
func toType (t reflectlite.Type ) Type {
345
+ if t == nil {
346
+ return nil
347
+ }
345
348
return (* rawType )(unsafe .Pointer (t .(* reflectlite.RawType )))
346
349
}
347
350
@@ -395,6 +398,30 @@ func (t *rawType) ConvertibleTo(u Type) bool {
395
398
panic ("unimplemented: (reflect.Type).ConvertibleTo()" )
396
399
}
397
400
401
+ func (t * rawType ) Elem () Type {
402
+ return toType (t .RawType .Elem ())
403
+ }
404
+
405
+ func (t * rawType ) Field (i int ) StructField {
406
+ f := t .RawType .Field (i )
407
+ return toStructField (f )
408
+ }
409
+
410
+ func (t * rawType ) FieldByIndex (index []int ) StructField {
411
+ f := t .RawType .FieldByIndex (index )
412
+ return toStructField (f )
413
+ }
414
+
415
+ func (t * rawType ) FieldByName (name string ) (StructField , bool ) {
416
+ f , ok := t .RawType .FieldByName (name )
417
+ return toStructField (f ), ok
418
+ }
419
+
420
+ func (t * rawType ) FieldByNameFunc (match func (string ) bool ) (StructField , bool ) {
421
+ f , ok := t .RawType .FieldByNameFunc (match )
422
+ return toStructField (f ), ok
423
+ }
424
+
398
425
func (t * rawType ) Implements (u Type ) bool {
399
426
return t .RawType .Implements (& (u .(* rawType ).RawType ))
400
427
}
@@ -431,11 +458,41 @@ func (t *rawType) Out(i int) Type {
431
458
panic ("unimplemented: (reflect.Type).Out()" )
432
459
}
433
460
434
- func (t * rawType ) Elem () Type {
435
- return toType (t .RawType .Elem ())
461
+ // A StructField describes a single field in a struct.
462
+ // This must be kept in sync with [reflectlite.StructField].
463
+ type StructField struct {
464
+ // Name indicates the field name.
465
+ Name string
466
+
467
+ // PkgPath is the package path where the struct containing this field is
468
+ // declared for unexported fields, or the empty string for exported fields.
469
+ PkgPath string
470
+
471
+ Type Type
472
+ Tag StructTag // field tag string
473
+ Offset uintptr
474
+ Index []int // index sequence for Type.FieldByIndex
475
+ Anonymous bool
476
+ }
477
+
478
+ func toStructField (f reflectlite.StructField ) StructField {
479
+ return StructField {
480
+ Name : f .Name ,
481
+ PkgPath : f .PkgPath ,
482
+ Type : toType (f .Type ),
483
+ Tag : f .Tag ,
484
+ Offset : f .Offset ,
485
+ Index : f .Index ,
486
+ Anonymous : f .Anonymous ,
487
+ }
488
+ }
489
+
490
+ // IsExported reports whether the field is exported.
491
+ func (f StructField ) IsExported () bool {
492
+ return f .PkgPath == ""
436
493
}
437
494
438
- type StructField = reflectlite.StructField
495
+ type StructTag = reflectlite.StructTag
439
496
440
497
func TypeFor [T any ]() Type {
441
498
return toType (reflectlite .TypeFor [T ]())
0 commit comments