# Intrusive data structure benefits over normal ones

**URL:** <https://users.rust-lang.org/t/intrusive-data-structure-benefits-over-normal-ones/142445>\
**Category:** help\
**Created:** [September 16, 2026, 6:43am UTC](https://users.rust-lang.org/t/intrusive-data-structure-benefits-over-normal-ones/142445 "2026-09-16T06:43:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkotsu](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/okkotsu/32/53930_2.png) [@okkotsu](https://users.rust-lang.org/u/okkotsu)\
**Post date:** [September 16, 2026, 6:43am UTC](https://users.rust-lang.org/t/intrusive-data-structure-benefits-over-normal-ones/142445/1 "2026-09-16T06:43:50Z")

</div>

hello, I am trying to understand intrusive data structure with this linked list example. I understand that for `T` to be an element of a single linked list it must store a pointer to `next` inside of `T`, and thus containing a list embedded inside `T` itself. But how does this help? How is this better as compared to a normal singly linked list and how does this reduce the overall allocation?

```rust

use std::cell::Cell;
use std::marker::PhantomData;
use std::ptr::NonNull;

struct Foo {
    value: i32,
    next: Cell<Option<NonNull<Foo>>>,
}

struct SingleLinkedIntrusiveList<'b, T>
where
    T: SingleLinkedIntrusiveListItem,
{
    first: Cell<Option<NonNull<T>>>,
    last: Cell<Option<NonNull<T>>>,
    _marker: core::marker::PhantomData<&'b ()>,
}

trait SingleLinkedIntrusiveListItem {
    fn next(&self) -> Option<NonNull<Self>>;
    fn set_next(&self, new_next: Option<NonNull<Self>>);
}

impl SingleLinkedIntrusiveListItem for Foo {
    fn next(&self) -> Option<NonNull<Self>> {
        self.next.get()
    }

    fn set_next(&self, new_next: Option<NonNull<Self>>) {
        self.next.set(new_next)
    }
}

```

---

<div class="post-metadata">

**Author:** ![SkiFire13](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/skifire13/32/17959_2.png) [@SkiFire13](https://users.rust-lang.org/u/SkiFire13)\
**Post date:** [September 16, 2026, 7:39am UTC](https://users.rust-lang.org/t/intrusive-data-structure-benefits-over-normal-ones/142445/2 "2026-09-16T07:39:23Z")

</div>

An intrusive linked list can be used in a more versatile way, for example:

- you can make a node part of more than one intrusive linked list
- you can store the nodes somewhere else instead of having them be managed by the linked list
- not all values need to have the same "shape"

---

<div class="post-metadata">

**Author:** ![okkotsu](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/okkotsu/32/53930_2.png) [@okkotsu](https://users.rust-lang.org/u/okkotsu)\
**Post date:** [September 16, 2026, 9:39am UTC](https://users.rust-lang.org/t/intrusive-data-structure-benefits-over-normal-ones/142445/3 "2026-09-16T09:39:50Z")

</div>

in the code example did we just create a simple linked list? or does it have any different properties when compared to a simple linked list?

> [@SkiFire13](#):
>
> - not all values need to have the same "shape"

could you please elaborate on this, thank you!
