github.com/MetalBlockchain/metalgo@v1.11.9/utils/zero.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package utils
     5  
     6  // Returns a new instance of a T.
     7  func Zero[T any]() T {
     8  	return *new(T)
     9  }
    10  
    11  // ZeroSlice sets all values of the provided slice to the type's zero value.
    12  //
    13  // This can be useful to ensure that the garbage collector doesn't hold
    14  // references to values that are no longer desired.
    15  func ZeroSlice[T any](s []T) {
    16  	for i := range s {
    17  		s[i] = *new(T)
    18  	}
    19  }