digitalmars.D.learn - How do I use null in a struct?
- =?UTF-8?B?VsOhY2xhdiBLb3rDoWs=?= (6/6) Nov 10 2018 I'm making a Rest API with vibe.d and I have a struct User.
- drug (3/9) Nov 10 2018 Probably you need Nullable?
- Sebastiaan Koppe (6/12) Nov 10 2018 You can use Optional like drug said, or you can use the @optional
- Heromyth (4/10) Nov 11 2018 Another choice:
I'm making a Rest API with vibe.d and I have a struct User. Sometimes I need to return only a few of the fields. So for example: return User(1, null, "John", null, null, ...); If I do this, an error occurs: cannot implicitly convert expression null of type typeof(null) to ... Thanks.
Nov 10 2018
On 10.11.2018 22:42, Václav Kozák wrote:I'm making a Rest API with vibe.d and I have a struct User. Sometimes I need to return only a few of the fields. So for example: return User(1, null, "John", null, null, ...); If I do this, an error occurs: cannot implicitly convert expression null of type typeof(null) to ... Thanks.Probably you need Nullable? https://dlang.org/phobos/std_typecons.html#Nullable
Nov 10 2018
On Saturday, 10 November 2018 at 19:42:47 UTC, Václav Kozák wrote:I'm making a Rest API with vibe.d and I have a struct User. Sometimes I need to return only a few of the fields. So for example: return User(1, null, "John", null, null, ...); If I do this, an error occurs: cannot implicitly convert expression null of type typeof(null) to ... Thanks.You can use Optional like drug said, or you can use the optional attribute [1]. optional will leave the field in its .init state, whereas with Optional its easier to detect the null state. [1] http://vibed.org/api/vibe.data.serialization/optional
Nov 10 2018
On Saturday, 10 November 2018 at 19:42:47 UTC, Václav Kozák wrote:I'm making a Rest API with vibe.d and I have a struct User. Sometimes I need to return only a few of the fields. So for example: return User(1, null, "John", null, null, ...); If I do this, an error occurs: cannot implicitly convert expression null of type typeof(null) to ... Thanks.Another choice: https://github.com/huntlabs/hunt/blob/master/source/hunt/lang/Nullable.d This Nullable is a class and we are using it.
Nov 11 2018