Skip to content

Commit

Permalink
Give ~struct{ *client } a name.
Browse files Browse the repository at this point in the history
This lets us refer to it outside the main package, and it also means
that CapList's constraint isn't exposing as much implementation detail.
  • Loading branch information
zenhack committed Aug 1, 2022
1 parent 0aa6c8d commit 2dfb9d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ func (id CapabilityID) GoString() string {
// A Client is a reference to a Cap'n Proto capability.
// The zero value is a null capability reference.
// It is safe to use from multiple goroutines.
type Client struct {
type Client ClientKind

// The underlying type of Client. We expose this so that
// we can use ~ClientKind as a constraint in generics to
// capture any capability type.
type ClientKind = struct {
*client
}

Expand Down
5 changes: 3 additions & 2 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,11 @@ func (s StructList[T]) String() string {
}

func (StructList[T]) DecodeFromPtr(p Ptr) StructList[T] {
return StructList[T]{ List: List{}.DecodeFromPtr(p) }
return StructList[T]{List: List{}.DecodeFromPtr(p)}
}

type CapList[T ~struct{*client}] PointerList
// A list of some Cap'n Proto capability type T.
type CapList[T ~ClientKind] PointerList

func (c CapList[T]) At(i int) (T, error) {
ptr, err := PointerList(c).At(i)
Expand Down

0 comments on commit 2dfb9d3

Please sign in to comment.