Source file test/typeparam/issue49295.go

     1  // run
     2  
     3  // Copyright 2021 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import "io"
    10  
    11  type Reader struct {
    12  	buf []byte
    13  }
    14  type Token *[16]byte
    15  
    16  func Read[T interface{ ~*[16]byte }](r *Reader) (t T, err error) {
    17  	if n := len(t); len(r.buf) >= n {
    18  		t = T(r.buf[:n])
    19  		r.buf = r.buf[n:]
    20  		return
    21  	}
    22  	err = io.EOF
    23  	return
    24  }
    25  
    26  func main() {
    27  	r := &Reader{buf: []byte("0123456789abcdef")}
    28  	token, err := Read[Token](r)
    29  	_, _ = token, err
    30  }
    31  

View as plain text