1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package thrift
21
22// Pointer is the generic (type parameter) version of the helper function that
23// converts types to pointer types.
24func Pointer[T any](v T) *T {
25	return &v
26}
27
28///////////////////////////////////////////////////////////////////////////////
29// This file is home to helpers that convert from various base types to
30// respective pointer types. This is necessary because Go does not permit
31// references to constants, nor can a pointer type to base type be allocated
32// and initialized in a single expression.
33//
34// E.g., this is not allowed:
35//
36//    var ip *int = &5
37//
38// But this *is* allowed:
39//
40//    func IntPtr(i int) *int { return &i }
41//    var ip *int = IntPtr(5)
42//
43// Since pointers to base types are commonplace as [optional] fields in
44// exported thrift structs, we factor such helpers here.
45///////////////////////////////////////////////////////////////////////////////
46
47func Float32Ptr(v float32) *float32 { return &v }
48func Float64Ptr(v float64) *float64 { return &v }
49func IntPtr(v int) *int             { return &v }
50func Int8Ptr(v int8) *int8          { return &v }
51func Int16Ptr(v int16) *int16       { return &v }
52func Int32Ptr(v int32) *int32       { return &v }
53func Int64Ptr(v int64) *int64       { return &v }
54func StringPtr(v string) *string    { return &v }
55func Uint32Ptr(v uint32) *uint32    { return &v }
56func Uint64Ptr(v uint64) *uint64    { return &v }
57func BoolPtr(v bool) *bool          { return &v }
58func ByteSlicePtr(v []byte) *[]byte { return &v }
59func TuuidPtr(v Tuuid) *Tuuid       { return &v }
60