github.com/enetx/g@v1.0.80/pkg/ref/of.go (about)

     1  // Package ref provides a utility function for creating a pointer to a value.
     2  // It is designed to simplify the process of obtaining a pointer to a value of any type.
     3  package ref
     4  
     5  // Of creates a pointer to the provided value of type 'E'.
     6  // The primary purpose of this function is to simplify the creation of pointers to values
     7  // without needing to use temporary variables.
     8  //
     9  // Parameters:
    10  //
    11  //	e: The value of type 'E' to create a pointer for.
    12  //
    13  // Returns:
    14  //
    15  //	*E: A pointer to the provided value 'e'.
    16  //
    17  // Example usage:
    18  //
    19  //	intValue := 42
    20  //	intPtr := ref.Of(intValue)
    21  //	fmt.Println(*intPtr)
    22  func Of[E any](e E) *E { return &e }