# Can i check struct validity using external method?

**URL:** https://discourse.julialang.org/t/can-i-check-struct-validity-using-external-method/106161
**Category:** New to Julia
**Created:** [November 13, 2023, 7:58pm UTC](https://discourse.julialang.org/t/can-i-check-struct-validity-using-external-method/106161 "2023-11-13T19:58:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)
#### Post date: [November 13, 2023, 7:58pm UTC](https://discourse.julialang.org/t/can-i-check-struct-validity-using-external-method/106161/1 "2023-11-13T19:58:05Z")

</div>

Hey,

I wanted to externalize my validity checks like that :

```julia
struct S{PT}
    par::PT
    function S(par)
        rez = new{typeof(par)}(par)
        check(rez) && return rez
    end
end
function check(rez::S{PT}) where PT
    # do my checks...
    return S.par < 2
end

S(1)
S(2)

```

The reason is that the check function is actually more general than this checker, and without it i have to recopy its code inside the constructor.

Why is julia yelling at me ?

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [November 13, 2023, 8:28pm UTC](https://discourse.julialang.org/t/can-i-check-struct-validity-using-external-method/106161/2 "2023-11-13T20:28:44Z")

</div>

You meant to write the check as

> [@lrnv](#):
>
> ```julia
> function check(rez::S{PT}) where PT
> # do my checks...
> # return S.par < 2
> return rez.par < 2
> end
> 
> ```
