We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I propose to add several converters to make code more readable.
Having this
converter toBencodeType(s: string) : BencodeType {.inline} = return BencodeType(kind: btString, s: s) converter toBencodeType(i: int) : BencodeType {.inline} = return BencodeType(kind: btInt, i: i) converter toBencodeType(seq: seq[BencodeType]) : BencodeType {.inline} = return BencodeType(kind: btList, l: seq) converter toBencodeType(t: OrderedTable[BencodeType, BencodeType]) : BencodeType {.inline} = return BencodeType(kind: btDict, d: t)
will allow to rewrite
var btDictSample1 = initOrderedTable[BencodeType, BencodeType]() btDictSample1[BencodeType(kind:btString, s:"name")] = BencodeType(kind:btString, s:"dmdm") btDictSample1[BencodeType(kind:btString, s:"lang")] = BencodeType(kind:btString, s:"nim") btDictSample1[BencodeType(kind:btString, s:"age")] = BencodeType(kind:btInt, i:50) btDictSample1[BencodeType(kind:btString, s:"alist")] = BencodeType(kind:btList, l:btListSample1) var testObjects = initOrderedTable[BencodeType, string]() testObjects[BencodeType(kind: btInt, i:12345)] = "i12345e" testObjects[BencodeType(kind: btList, l:btListSample1)] = "li1e2:hie" testObjects[BencodeType(kind:btDict, d:btDictSample1)] = "d4:name4:dmdm4:lang3:nim3:agei50e5:alistli1e2:hiee"
in more compact way:
var btDictSample1 = initOrderedTable[BencodeType, BencodeType]() btDictSample1["name"] = "dmdm" btDictSample1["lang"] = "nim" btDictSample1["age"] = 50 btDictSample1["alist"] = btListSample1 var testObjects = initOrderedTable[BencodeType, string]() testObjects[12345] = "i12345e" testObjects[btListSample1] = "li1e2:hie" testObjects[btDictSample1] = "d4:name4:dmdm4:lang3:nim3:agei50e5:alistli1e2:hiee"
Well, the last two are quite code-specific, but it's better to have int and string converters out of the box.
int
string
The text was updated successfully, but these errors were encountered:
Oh! I didn't know about converters at all. Thanks a lot! please feel welcome to add them yourself as I'll be learning a bit about them
converters
Sorry, something went wrong.
No branches or pull requests
I propose to add several converters to make code more readable.
Having this
will allow to rewrite
in more compact way:
Well, the last two are quite code-specific, but it's better to have
int
andstring
converters out of the box.The text was updated successfully, but these errors were encountered: