# Isstructtype()

**URL:** https://discourse.julialang.org/t/isstructtype/88268
**Category:** General Usage
**Tags:** parametric-types, functions, structtypes
**Created:** [October 5, 2022, 2:59am UTC](https://discourse.julialang.org/t/isstructtype/88268 "2022-10-05T02:59:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)
#### Post date: [October 5, 2022, 2:59am UTC](https://discourse.julialang.org/t/isstructtype/88268/1 "2022-10-05T02:59:32Z")

</div>

Is it possible to do something like

```julia
function my_func( x::I ) where isstructtype(I)

    #function body
    
end

```

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [October 5, 2022, 3:01am UTC](https://discourse.julialang.org/t/isstructtype/88268/2 "2022-10-05T03:01:00Z")

</div>

WhereTraits.jl supports that.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [October 5, 2022, 3:15am UTC](https://discourse.julialang.org/t/isstructtype/88268/3 "2022-10-05T03:15:14Z")

</div>

note that if you’re coming from Matlab (which I’m willing to bet you are), this won’t do what you want. instead you want to leave this untyped.

---

<div class="post-metadata">

### Author: ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)
#### Post date: [October 5, 2022, 3:22am UTC](https://discourse.julialang.org/t/isstructtype/88268/4 "2022-10-05T03:22:30Z")

</div>

Thanks Jar.  
Thinking of suggesting this for use in a couple of packages.

For example NamedTupleTools.jl has a specific function `ntfromstruct()` for converting structs.  
With the below line added. The user could instead use the generic NamedTuple function.

`@traits NamedTuple( x ) where isstructtype(typeof(x)) = ntfromstruct( x )`

Similarly, the `Dictionary()` function in Dictionaries.jl converts many different types of input (but not currently structs). The below line would allow it to do so.

`@traits Dictionary( x ) where isstructtype(typeof(x)) = Dictionary( ntfromstruct( x ))`

@Oscar_Smith  
I’m not a matlab user. Not sure if this affects your advice.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [October 5, 2022, 4:37am UTC](https://discourse.julialang.org/t/isstructtype/88268/5 "2022-10-05T04:37:00Z")

</div>

Out of curiosity, what kinds of objects would be permitted to dispatch through this? We don’t have limits on dispatch through functions.

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [October 5, 2022, 5:49am UTC](https://discourse.julialang.org/t/isstructtype/88268/6 "2022-10-05T05:49:29Z")

</div>

Bit of a warning, a lot of unexpected types are `isstructtype`.
