Add pragma accessors
This library requires a forked macros module, so export accessors that would prevent a downstream library from having the same problems with std/macros.
This commit is contained in:
parent
f32e783e0b
commit
ddc26f0c71
|
@ -635,6 +635,18 @@ template preservesRecord*(label: string) {.pragma.}
|
||||||
## Serialize this object or tuple as a record.
|
## Serialize this object or tuple as a record.
|
||||||
## See ``toPreserve``.
|
## See ``toPreserve``.
|
||||||
|
|
||||||
|
proc hasPreservesRecordPragma*(T: typedesc): bool =
|
||||||
|
## Test if a type has a `{.preservesRecord: "…".}` pragma attached.
|
||||||
|
hasCustomPragma(T, preservesRecord)
|
||||||
|
|
||||||
|
proc recordLabel*(T: typedesc): string =
|
||||||
|
## Get the record label set by a pragma on a type.
|
||||||
|
runnableExamples:
|
||||||
|
type Foo {.preservesRecord: "bar".} = object
|
||||||
|
n: int
|
||||||
|
assert recordLabel(Foo) == "bar"
|
||||||
|
T.getCustomPragmaVal(preservesRecord)
|
||||||
|
|
||||||
template preservesTuple*() {.pragma.}
|
template preservesTuple*() {.pragma.}
|
||||||
## Serialize this object or tuple as a tuple.
|
## Serialize this object or tuple as a tuple.
|
||||||
## See ``toPreserve``.
|
## See ``toPreserve``.
|
||||||
|
@ -643,10 +655,18 @@ template preservesTupleTail*() {.pragma.}
|
||||||
## Serialize this object field to the end of its containing tuple.
|
## Serialize this object field to the end of its containing tuple.
|
||||||
## See ``toPreserve``.
|
## See ``toPreserve``.
|
||||||
|
|
||||||
|
proc hasPreservesTuplePragma*(T: typedesc): bool =
|
||||||
|
## Test if a type has a `preservesTuple` pragma attached.
|
||||||
|
hasCustomPragma(T, preservesTuple)
|
||||||
|
|
||||||
template preservesDictionary*() {.pragma.}
|
template preservesDictionary*() {.pragma.}
|
||||||
## Serialize this object or tuple as a dictionary.
|
## Serialize this object or tuple as a dictionary.
|
||||||
## See ``toPreserve``.
|
## See ``toPreserve``.
|
||||||
|
|
||||||
|
proc hasPreservesDictionaryPragma*(T: typedesc): bool =
|
||||||
|
## Test if a type has a `preservesDictionary` pragma attached.
|
||||||
|
hasCustomPragma(T, preservesDictionary)
|
||||||
|
|
||||||
template preservesOr*() {.pragma.}
|
template preservesOr*() {.pragma.}
|
||||||
## Serialize this object as an ``or`` alternative.
|
## Serialize this object as an ``or`` alternative.
|
||||||
## See ``toPreserve``.
|
## See ``toPreserve``.
|
||||||
|
|
Loading…
Reference in New Issue