gust icon indicating copy to clipboard operation
gust copied to clipboard

Implementation question: Option's secondary pointer

Open zweix123 opened this issue 1 year ago • 1 comments
trafficstars

I have a question, why does the implementation of Option use a second level pointer? I have reviewed the implementation of the relevant methods, can using a first level pointer also meet the requirements?

May I ask how the design was considered at that time?

zweix123 avatar Nov 11 '24 07:11 zweix123

I seem to understand a bit.

func TestZweix(t *testing.T) {
	type F struct {
		A int
		B string
	}
	opt1 := gust.Some[*F](&F{A: 1, B: "2"})
	opt2 := gust.Some[*F](nil)
}

To identify such scenarios.

zweix123 avatar Nov 11 '24 07:11 zweix123