# Recursively defining a type without using an Option

**URL:** <https://internals.rust-lang.org/t/recursively-defining-a-type-without-using-an-option/495>\
**Category:** ideas (deprecated)\
**Created:** [September 12, 2014, 6:29am UTC](https://internals.rust-lang.org/t/recursively-defining-a-type-without-using-an-option/495 "2014-09-12T06:29:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stebalien](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/stebalien/32/228_2.png) [@stebalien](https://internals.rust-lang.org/u/stebalien)\
**Post date:** [September 12, 2014, 6:29am UTC](https://internals.rust-lang.org/t/recursively-defining-a-type-without-using-an-option/495/1 "2014-09-12T06:29:53Z")

</div>

Currently, the following doesn’t work because the types cannot be instantiated without instances of themselves:

```rust
struct Outer {
    inner: Inner
}
struct Inner {
    outer: Box<Outer>
}
fn main() {
    let outer : Outer;
    outer = Outer { inner: Inner { outer: box outer };
}

```

However, this identical C program does work:

```rust
struct Inner {
    struct Outer * outer;
};
struct Outer {
    struct Inner inner;
};
int main() {
    struct Outer outer = { .inner = { .outer = &outer } };
    return 0;
}

```

So, is there any chance we could drop this error? Taking the address of an uninitialized variable is perfectly safe and the pattern of children pointing to parents is fairly common. While one could use an Option type, this would lead to run time checking of something that can (and should) be checked at compile time checking.

---

<div class="post-metadata">

**Author:** ![bluss](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bluss/32/2264_2.png) [@bluss](https://internals.rust-lang.org/u/bluss)\
**Post date:** [September 12, 2014, 7:28am UTC](https://internals.rust-lang.org/t/recursively-defining-a-type-without-using-an-option/495/2 "2014-09-12T07:28:59Z")

</div>

The programs are not identical. Box is an owning and a unique pointer, it simply cannot be in both places at once. You need `*mut Outer` to write the “identical” program in Rust.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:22am UTC](https://internals.rust-lang.org/t/recursively-defining-a-type-without-using-an-option/495/3 "2019-03-25T08:22:52Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
