-
Notifications
You must be signed in to change notification settings - Fork 41
/
name.jl
41 lines (30 loc) · 992 Bytes
/
name.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
AbstractName
Abstract supertype for name wrappers.
"""
abstract type AbstractName end
Base.convert(T::Type{<:AbstractString}, name::AbstractName) = convert(T, string(name))
"""
NoName <: AbstractName
NoName()
NoName specifies an array is not named, and is the default `name`
value for all `AbstractDimArray`s.
"""
struct NoName <: AbstractName end
Base.Symbol(::NoName) = Symbol("")
Base.string(::NoName) = ""
"""
Name <: AbstractName
Name(name::Union{Symbol,Name) => Name
Name(name::NoName) => NoName
Name wrapper. This lets arrays keep symbol names when the array wrapper needs
to be `isbits`, like for use on GPUs. It makes the name a property of the type.
It's not necessary to use in normal use, a symbol is probably easier.
"""
struct Name{X} <: AbstractName end
Name(name::Symbol) = Name{name}()
Name(name::NoName) = NoName()
Name(name::Name) = name
Base.Symbol(::Name{X}) where X = X
Base.string(::Name{X}) where X = string(X)
name(x::Name) = x