mirror of https://github.com/Hax-io/libpb
- Moved back to more clean templating method (for now till a fix can be found for the type lookups for issue #7)
This commit is contained in:
parent
c89d6bd8b6
commit
4fc4242c1e
|
@ -3,14 +3,6 @@ module libpb.deserialization;
|
|||
import std.json;
|
||||
import libpb.exceptions : RemoteFieldMissing;
|
||||
|
||||
/**
|
||||
* T
|
||||
*
|
||||
* Params:
|
||||
* RecordType = type of the struct to construct
|
||||
*/
|
||||
mixin template T(RecordType)
|
||||
{
|
||||
import std.traits : FieldTypeTuple, FieldNameTuple;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +15,7 @@ mixin template T(RecordType)
|
|||
* cannot be found within the prpvided JSONValue `jsonIn`.
|
||||
* Returns: an instance of RecordType
|
||||
*/
|
||||
public RecordType fromJSON(JSONValue jsonIn)
|
||||
public RecordType fromJSON(RecordType)(JSONValue jsonIn)
|
||||
{
|
||||
RecordType record;
|
||||
|
||||
|
@ -41,9 +33,12 @@ mixin template T(RecordType)
|
|||
// pragma(msg, structValues[cnt]);
|
||||
}
|
||||
|
||||
debug(dbg)
|
||||
{
|
||||
pragma(msg, "Bruh type");
|
||||
pragma(msg, structTypes[cnt]);
|
||||
// pragma(msg, __traits(identifier, mixin(structTypes[cnt])));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -134,7 +129,6 @@ mixin template T(RecordType)
|
|||
|
||||
return record;
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
|
@ -160,8 +154,7 @@ unittest
|
|||
}
|
||||
`);
|
||||
|
||||
mixin T!(Person);
|
||||
Person person = fromJSON(json);
|
||||
Person person = fromJSON!(Person)(json);
|
||||
|
||||
debug(dbg)
|
||||
{
|
||||
|
@ -199,10 +192,9 @@ unittest
|
|||
}
|
||||
`);
|
||||
|
||||
mixin T!(Person);
|
||||
try
|
||||
{
|
||||
Person person = fromJSON(json);
|
||||
Person person = fromJSON!(Person)(json);
|
||||
assert(false);
|
||||
}
|
||||
catch(RemoteFieldMissing)
|
||||
|
|
|
@ -158,8 +158,7 @@ public class PocketBase
|
|||
}
|
||||
}
|
||||
|
||||
mixin T!(RecordType);
|
||||
recordsOut ~= fromJSON(returnedItem);
|
||||
recordsOut ~= fromJSON!(RecordType)(returnedItem);
|
||||
}
|
||||
|
||||
return recordsOut;
|
||||
|
@ -269,8 +268,7 @@ public class PocketBase
|
|||
responseJSON["passwordConfirm"] = "";
|
||||
}
|
||||
|
||||
mixin T!(RecordType);
|
||||
recordOut = fromJSON(responseJSON);
|
||||
recordOut = fromJSON!(RecordType)(responseJSON);
|
||||
|
||||
return recordOut;
|
||||
}
|
||||
|
@ -350,9 +348,7 @@ public class PocketBase
|
|||
recordResponse["email"] = "";
|
||||
}
|
||||
|
||||
|
||||
mixin T!(RecordType);
|
||||
recordOut = fromJSON(recordResponse);
|
||||
recordOut = fromJSON!(RecordType)(recordResponse);
|
||||
|
||||
// Store the token
|
||||
token = responseJSON["token"].str();
|
||||
|
@ -451,8 +447,7 @@ public class PocketBase
|
|||
}
|
||||
}
|
||||
|
||||
mixin T!(RecordType);
|
||||
recordOut = fromJSON(responseJSON);
|
||||
recordOut = fromJSON!(RecordType)(responseJSON);
|
||||
|
||||
return recordOut;
|
||||
}
|
||||
|
@ -557,8 +552,7 @@ public class PocketBase
|
|||
}
|
||||
}
|
||||
|
||||
mixin T!(RecordType);
|
||||
recordOut = fromJSON(responseJSON);
|
||||
recordOut = fromJSON!(RecordType)(responseJSON);
|
||||
|
||||
return recordOut;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue