diff --git a/.all-contributorsrc b/.all-contributorsrc
index 0ed1c67de7..1de8d7ac03 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1558,6 +1558,15 @@
"contributions": [
"code"
]
+ },
+ {
+ "login": "a-h",
+ "name": "Adrian Hesketh",
+ "avatar_url": "https://avatars.githubusercontent.com/u/1029947?v=4",
+ "profile": "http://adrianhesketh.com/",
+ "contributions": [
+ "code"
+ ]
}
],
"repoType": "github",
diff --git a/README.md b/README.md
index 87a3a7a96f..b08b239b8c 100644
--- a/README.md
+++ b/README.md
@@ -61,199 +61,200 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Abdallah Hodieb π |
Adam Ruka π π» π§ π |
Adrian Dimech π» |
+ Adrian Hesketh π» |
Alex Pulver π |
- Andi Pabst π |
+ Andi Pabst π |
Andrew Wason π π» |
Andy Slezak π» |
Ansgar Mertens π§ π» π |
Anshul Guleria π€ |
Ari Palo π€ |
Armaan Tobaccowalla π |
- BartΕomiej Jurek π |
+ BartΕomiej Jurek π |
Ben Bridts π |
Ben Chaimberg π |
Ben Farr π |
Ben Walters π€ |
Benjamin Macher π |
Benjamin Maizels π» π |
- Bervianto Leo Pratama π§ |
+ Bervianto Leo Pratama π§ |
Bill Cauchois π€ |
Brecht Verhoeve π€ |
Breland Miley π» |
CaerusKaru π» π§ |
Calvin Combs π» π |
Camilo BermΓΊdez π |
- Campion Fellin π» |
+ Campion Fellin π» |
Carter Van Deuren π |
Chris Garvis π |
Christian Moore π |
Christophe Vico π |
Christopher Currie π» π€ |
Christopher Rybicki π π π» |
- CommanderRoot π» |
+ CommanderRoot π» |
Cory Hall π |
Cristian MΔgheruΘan-Stanciu π |
CyrusNajmabadi π π€ |
Damian Silbergleith π» π |
Daniel Dinu π π» |
Daniel Schmidt π π» |
- Daniel Schroeder π π» π π€ π§ |
+ Daniel Schroeder π π» π π€ π§ |
Dave Slotnick π |
David Bell π» |
Donald Stufft π π» π€ π |
Dongie Agnir π» π |
Eduardo Rabelo π |
Eduardo Sena S. Rosa π |
- Elad Ben-Israel π π» π€ π§ π π’ |
+ Elad Ben-Israel π π» π€ π§ π π’ |
Eli Polonsky π π» π€ π§ π |
Eric Z. Beard π |
Erik Karlsson π |
Eugene Kozlov π» |
Fabio Gentile π |
Florian Eitel π€ |
- Glib Shpychka π |
+ Glib Shpychka π |
Graham Lea π€ π |
Greg Lucas π» |
Hamza Assyad π π» π€ π |
Hari Pachuveetil π π |
Hsing-Hui Hsu π» π π€ π |
Ikko Ashimine π |
- James π π» |
+ James π π» |
James Kelley π |
James Mead π» |
James Siri π» π§ |
Jason Del Ponte π€ π |
Jason Fulghum π€ π π |
Jeff Malins π» |
- Jerry Kindall π π€ |
+ Jerry Kindall π π€ |
Jimmy Gaussen π€ |
Johannes Weber π |
John Pantzlaff π» |
Jon Steinich π π€ π» |
Joseph Lawson π |
Joseph Martin π |
- Junix π |
+ Junix π |
Justin Frahm π |
Justin Taylor π |
Kaizen Conroy π» π |
Kaizen Conroy π» |
Kaushik Borra π |
Knut O. Hellan π |
- Kyle Thomson π» π |
+ Kyle Thomson π» π |
Leandro Padua π |
Liang Zhou π π» |
Madeline Kusters π» π |
Maja S Bratseth π |
Marcos Diez π |
Mark Nielsen π» |
- Matthew Bonig π π |
+ Matthew Bonig π π |
Matthew Pirocchi π» π€ π |
Meng Xin Zhu π |
Michael Neil π§ |
Mike Lane π |
Mitch Garnaat π π» π€ π |
Mitchell Valine π π» π€ π§ π |
- Mohamad Soufan π |
+ Mohamad Soufan π |
Mykola Mogylenko π |
Naumel π |
Neta Nir π» π€ π§ π |
Nick Lynch π π» π§ π |
Niranjan Jayakar π π» π€ π§ π |
Noah Litov π» π§ π |
- Otavio Macedo π» π |
+ Otavio Macedo π» π |
PIDZ - Bart π€ |
Peter Woodworth π§ |
Petr Kacer π |
Petra Barus π» |
Philip Cali π€ |
Quentin Loos π€ |
- Raphael π |
+ Raphael π |
Richard H Boyd π |
Rico Huijbers π π» π€ π§ π |
Romain Marcadier π π» π¨ π€ π§ π π |
SADIK KUZU π |
SK π€ |
Sam Fink π» π |
- Sam Goodwin π |
+ Sam Goodwin π |
Sebastian Korfmann π π» π€ |
Sepehr Laal π |
Shane Witbeck π€ |
Shiv Lakshminarayan π» π§ π |
Somaya π» π€ π§ π |
Stephen Kuenzli π |
- Takahiro Sugiura π |
+ Takahiro Sugiura π |
The Gitter Badger π» π§ |
Thomas Poignant π |
Thomas Steinbach π |
Thorsten Hoeger π» |
Tim Wagner π π€ |
Tobias Lidskog π» |
- Tom Bonner π |
+ Tom Bonner π |
Ty Coghlan π |
Tyler van Hensbergen π€ |
Vlad Hrybok π |
Vladimir Shchur π |
Will Bender π |
Yan Zhulanow π» |
- Yigong Liu π π€ |
+ Yigong Liu π π€ |
Zach Bienenfeld π |
ajnarang π€ |
aniljava π» |
arnogeurts-sqills π π» |
cn-cit π |
deccy-mcc π |
- dependabot-preview[bot] π π§ |
+ dependabot-preview[bot] π π§ |
dependabot[bot] π§ |
dheffx π |
gregswdl π |
guyroberts21 π |
mattBrzezinski π |
mergify π§ |
- mergify[bot] π§ |
+ mergify[bot] π§ |
nathannaveen π§ |
seiyashima42 π π» π |
sullis π» |
diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go b/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go
index 8228f9a41d..54f7bc2fce 100644
--- a/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go
+++ b/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go
@@ -2,23 +2,45 @@ package jsii
import "time"
-// Bool obtains a pointer to the provided bool.
-func Bool(v bool) *bool { return &v }
+type basicType interface {
+ bool | string | float64 | time.Time
+}
-// Bools obtains a pointer to a slice of pointers to all the provided booleans.
-func Bools(v ...bool) *[]*bool {
- slice := make([]*bool, len(v))
+// Ptr returns a pointer to the provided value.
+func Ptr[T basicType](v T) *T {
+ return &v
+}
+
+// PtrSlice returns a pointer to a slice of pointers to all of the provided values.
+func PtrSlice[T basicType](v ...T) *[]*T {
+ slice := make([]*T, len(v))
for i := 0; i < len(v); i++ {
- slice[i] = Bool(v[i])
+ slice[i] = Ptr(v[i])
}
return &slice
}
-// Number obtains a pointer to the provided float64.
-func Number(v float64) *float64 { return &v }
+// Bool returns a pointer to the provided bool.
+func Bool(v bool) *bool { return Ptr(v) }
+
+// Bools returns a pointer to a slice of pointers to all of the provided booleans.
+func Bools(v ...bool) *[]*bool {
+ return PtrSlice(v...)
+}
+
+type numberType interface {
+ ~float32 | ~float64 |
+ ~int | ~int8 | ~int16 | ~int32 | ~int64 |
+ ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
+}
-// Numbers obtains a pointer to a slice of pointers to all the provided numbers.
-func Numbers(v ...float64) *[]*float64 {
+// Number returns a pointer to the provided float64.
+func Number[T numberType](v T) *float64 {
+ return Ptr(float64(v))
+}
+
+// Numbers returns a pointer to a slice of pointers to all of the provided numbers.
+func Numbers[T numberType](v ...T) *[]*float64 {
slice := make([]*float64, len(v))
for i := 0; i < len(v); i++ {
slice[i] = Number(v[i])
@@ -26,26 +48,18 @@ func Numbers(v ...float64) *[]*float64 {
return &slice
}
-// String obtains a pointer to the provided string.
-func String(v string) *string { return &v }
+// String returns a pointer to the provided string.
+func String(v string) *string { return Ptr(v) }
-// Strings obtains a pointer to a slice of pointers to all the provided strings.
+// Strings returns a pointer to a slice of pointers to all of the provided strings.
func Strings(v ...string) *[]*string {
- slice := make([]*string, len(v))
- for i := 0; i < len(v); i++ {
- slice[i] = String(v[i])
- }
- return &slice
+ return PtrSlice(v...)
}
-// Time obtains a pointer to the provided time.Time.
-func Time(v time.Time) *time.Time { return &v }
+// Time returns a pointer to the provided time.Time.
+func Time(v time.Time) *time.Time { return Ptr(v) }
-// Times obtains a pointer to a slice of pointers to all the provided time.Time.
+// Times returns a pointer to a slice of pointers to all of the provided time.Time values.
func Times(v ...time.Time) *[]*time.Time {
- slice := make([]*time.Time, len(v))
- for i := 0; i < len(v); i++ {
- slice[i] = Time(v[i])
- }
- return &slice
+ return PtrSlice(v...)
}
diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go b/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go
index dd25ee3f9e..4287dbeda9 100644
--- a/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go
+++ b/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go
@@ -7,6 +7,26 @@ import (
"github.com/stretchr/testify/assert"
)
+func TestV(t *testing.T) {
+ // Bool
+ assert.Equal(t, true, *Ptr(true))
+ assert.Equal(t, false, *Ptr(false))
+ // Bools
+ assert.Equal(t, []*bool{Bool(true), Bool(false), Bool(false), Bool(true)}, *PtrSlice(true, false, false, true))
+ // Float64 is supported because it doesn't require conversion.
+ assert.Equal(t, 123.45, *Ptr(123.45))
+ assert.Equal(t, float64(123.45), *Ptr(float64(123.45)))
+ // String
+ assert.Equal(t, "Hello", *String("Hello"))
+ // Strings
+ assert.Equal(t, []*string{String("Hello"), String("World")}, *Strings("Hello", "World"))
+ // Time
+ now := time.Now()
+ assert.Equal(t, now, *Time(now))
+ // Times
+ assert.Equal(t, []*time.Time{Time(now)}, *Times(now))
+}
+
func TestBool(t *testing.T) {
assert.Equal(t, true, *Bool(true))
assert.Equal(t, false, *Bool(false))
@@ -19,6 +39,21 @@ func TestBools(t *testing.T) {
func TestNumber(t *testing.T) {
assert.Equal(t, 123.45, *Number(123.45))
assert.Equal(t, 1337.0, *Number(1337))
+ // Floats.
+ assert.Equal(t, float64(float32(123.45)), *Number(float32(123.45)))
+ assert.Equal(t, float64(123.45), *Number(float64(123.45)))
+ // Ints.
+ assert.Equal(t, float64(1337), *Number(int(1337)))
+ // Signed.
+ assert.Equal(t, float64(127), *Number(int8(127)))
+ assert.Equal(t, float64(1337), *Number(int16(1337)))
+ assert.Equal(t, float64(1337), *Number(int32(1337)))
+ assert.Equal(t, float64(1337), *Number(int64(1337)))
+ // Unsigned.
+ assert.Equal(t, float64(127), *Number(uint8(127)))
+ assert.Equal(t, float64(1337), *Number(uint16(1337)))
+ assert.Equal(t, float64(1337), *Number(uint32(1337)))
+ assert.Equal(t, float64(1337), *Number(uint64(1337)))
}
func TestNumbers(t *testing.T) {