Re: [go-nuts] How to cast *interface{} into *T ?

2022-11-28 Thread Denis P
quot;. It has "variables", which is >> *probably* what you mean. >> >> On Fri, Nov 25, 2022 at 10:55 AM Denis P wrote: >> >>> Thank you everyone for your help. >>> The problem still exists. >>> I am looking for a solution where s and s2

Re: [go-nuts] How to cast *interface{} into *T ?

2022-11-25 Thread Denis P
Thank you everyone for your help. The problem still exists. I am looking for a solution where s and s2 point to the same instance. The current example proves they are different instances. https://go.dev/play/p/_JyfJelhIy4 The main goal is to store any type in a wrapper and then get the reference

Re: [go-nuts] How to cast *interface{} into *T ?

2022-11-24 Thread Denis P
Ok, finally got it: https://go.dev/play/p/QFQOpqWsR6S Thanks everyone, especially Axel On Thursday, 24 November 2022 at 23:14:27 UTC Denis P wrote: > Ok, looks like it doesn't work. > > I have got the following error: > panic: interface conversion: interface {} is MyStruct, not

Re: [go-nuts] How to cast *interface{} into *T ?

2022-11-24 Thread Denis P
el.wa...@googlemail.com wrote: > Hi, > > > On Thu, Nov 24, 2022 at 11:16 PM Denis P wrote: > >> Hi guys, tried to look everywhere and cannot find an answer. >> >> So literally I have this: >> ``` >> var result interface{} = &MyStruct{} >> >>

[go-nuts] How to cast *interface{} into *T ?

2022-11-24 Thread Denis P
Hi guys, tried to look everywhere and cannot find an answer. So literally I have this: ``` var result interface{} = &MyStruct{} ... return result.(*MyStruct) // Error: invalid operation: result (variable of type *interface{}) is not an interface ``` Is there any way to get the &MyStruct as a

[go-nuts] Method chaining in multiple lines

2022-11-24 Thread Denis P
Hi guys, I am struggling with making my code work in a way that multiple methods called in multiline approach. Does any gopher has an answer is there any solution to this: ``` type MyStuff struct { } func CreateMyStuff() MyStuff {} func (s MyStuff) DoJobOne() MyStuff {} func (s MyStuff) DoJob

[go-nuts] cannot initialize 1 variables with 2 values

2022-11-23 Thread Denis P
Hi guys, Does anyone know how to pass it properly and without adding extra lines of code? ``` func GetAsOr[T any](t interface{}, e error) (T, error) { return t.(T), e } func (s ServiceProvider) GetServiceOr() (interface{}, error) { } result := GetAsOr[MyObj](services.GetServiceOr()