This module defines compile-time reflection procs for working with types.
この API は不安定です。
プロシージャ
proc name(t: typedesc): string {...}{.magic: "TypeTrait".}
-
Returns the name of the given type.
Alias for system.`$`(t) since Nim v0.20.
ソース 編集 proc arity(t: typedesc): int {...}{.magic: "TypeTrait".}
-
Returns the arity of the given type. This is the number of "type" components or the number of generic parameters a given type t has.
用例:
assert arity(seq[string]) == 1 assert arity(array[3, int]) == 2 assert arity((int, int, float, string)) == 4
ソース 編集 proc genericHead(t: typedesc): typedesc {...}{.magic: "TypeTrait".}
-
Accepts an instantiated generic type and returns its uninstantiated form.
For example:
- seq[int].genericHead will be just seq
- seq[int].genericHead[float] will be seq[float]
A compile-time error will be produced if the supplied type is not generic.
関連:
用例:
type Functor[A] = concept f type MatchedGenericType = genericHead(f.type) # `f` will be a value of a type such as `Option[T]` # `MatchedGenericType` will become the `Option` type
ソース 編集 proc stripGenericParams(t: typedesc): typedesc {...}{.magic: "TypeTrait".}
- This trait is similar to genericHead, but instead of producing error for non-generic types, it will just return them unmodified. ソース 編集
proc supportsCopyMem(t: typedesc): bool {...}{.magic: "TypeTrait".}
-
This trait returns true iff the type t is safe to use for copyMem.
Other languages name a type like these blob.
ソース 編集 proc isNamedTuple(T: typedesc): bool
- Return true for named tuples, false for any other type. ソース 編集