# Creating custom type of enumerations of symbols

**URL:** https://discourse.julialang.org/t/creating-custom-type-of-enumerations-of-symbols/18635
**Category:** New to Julia
**Tags:** structtypes
**Created:** [December 13, 2018, 5:05pm UTC](https://discourse.julialang.org/t/creating-custom-type-of-enumerations-of-symbols/18635 "2018-12-13T17:05:21Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [December 13, 2018, 8:48pm UTC](https://discourse.julialang.org/t/creating-custom-type-of-enumerations-of-symbols/18635/7 "2018-12-13T20:48:32Z")

</div>

Maybe:

```julia
struct ConstrainedSymbol{T}
	a::Symbol

	ConstrainedSymbol(a) = ConstrainedSymbol{Any}(a)
	ConstrainedSymbol{Any}(a) = new{Any}(a)
	ConstrainedSymbol{T}(a) where {T} = a in T ? new{T}(a) : throw("Symbol :$a is not in the supported set of symbols $T.")
end
Base.convert(::Type{Symbol}, s::ConstrainedSymbol) = s.a
Base.Symbol(s::ConstrainedSymbol) = s.a

```

```julia
julia> s = ConstrainedSymbol{(:a, :b)}(:a)
ConstrainedSymbol{(:a, :b)}(:a)

julia> s = ConstrainedSymbol{(:a, :b)}(:b)
ConstrainedSymbol{(:a, :b)}(:b)

julia> s = ConstrainedSymbol{(:a, :b)}(:c)
ERROR: "Symbol :c is not in the supported set of symbols (:a, :b)."
Stacktrace:
 [1] ConstrainedSymbol{(:a, :b)}(::Symbol) at .\REPL[1]:6
 [2] top-level scope at none:0

julia> s = ConstrainedSymbol(:c)
ConstrainedSymbol{Any}(:c)

julia> Symbol(s)
:c

```

---

_[View the full topic](https://discourse.julialang.org/t/creating-custom-type-of-enumerations-of-symbols/18635)._
