Standard library / slices
slices.Clip()
Restricts capacity to length without copying elements; it does not guarantee freeing the backing allocation. Preserves nil. Expected stdout: '2 2\n'.
Formal Syntax & Structure
go syntaxgo
func Clip[S ~[]E, E any](s S) SParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | S | Input slice; may share its backing array. |
Return Value
S
Restricts capacity to length without copying elements; it does not guarantee freeing the backing allocation. Preserves nil.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { a := make([]int, 2, 8) b := slices.Clip(a) fmt.Println(len(b), cap(b))}