knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/ptr/ptr.go (about)

     1  /*
     2  Copyright 2019 The Knative Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ptr
    18  
    19  import "time"
    20  
    21  // Int32 is a helper for turning integers into pointers for use in
    22  // API types that want *int32.
    23  func Int32(i int32) *int32 {
    24  	return &i
    25  }
    26  
    27  // Int64 is a helper for turning integers into pointers for use in
    28  // API types that want *int64.
    29  func Int64(i int64) *int64 {
    30  	return &i
    31  }
    32  
    33  // Float32 is a helper for turning floats into pointers for use in
    34  // API types that want *float32.
    35  func Float32(f float32) *float32 {
    36  	return &f
    37  }
    38  
    39  // Float64 is a helper for turning floats into pointers for use in
    40  // API types that want *float64.
    41  func Float64(f float64) *float64 {
    42  	return &f
    43  }
    44  
    45  // Bool is a helper for turning bools into pointers for use in
    46  // API types that want *bool.
    47  func Bool(b bool) *bool {
    48  	return &b
    49  }
    50  
    51  // String is a helper for turning strings into pointers for use in
    52  // API types that want *string.
    53  func String(s string) *string {
    54  	return &s
    55  }
    56  
    57  // Duration is a helper for turning time.Duration into pointers for use in
    58  // API types that want *time.Duration.
    59  func Duration(t time.Duration) *time.Duration {
    60  	return &t
    61  }
    62  
    63  // Time is a helper for turning a const time.Time into a pointer for use in
    64  // API types that want *time.Duration.
    65  func Time(t time.Time) *time.Time {
    66  	return &t
    67  }