# Struct's extendability

**URL:** <https://forum.modular.com/t/structs-extendability/591>\
**Category:** Mojo\
**Tags:** discussion, feature-request, mojo-compiler, llvm, 24\_6\
**Created:** [February 19, 2025, 8:13am UTC](https://forum.modular.com/t/structs-extendability/591 "2025-02-19T08:13:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jymchng](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@jymchng](https://forum.modular.com/u/jymchng)\
**Post date:** [February 19, 2025, 8:13am UTC](https://forum.modular.com/t/structs-extendability/591/1 "2025-02-19T08:13:23Z")

</div>

Given Mojo’s syntax of ‘implementing’ a trait for a struct, e.g.:

```mojo

trait Permissable:
    ...

struct Permission(Permissable):
    ...

```

This would mean that there is no way to ‘implement’ a local trait on a foreign type syntactically because I am unable to write something like:

```mojo
from foreign_package import ForeignType

struct ForeignType(*ForeignType. __traits__ , Permissable):
    ...

```

In Rust, the `impl LocalTrait for ForeignType {..};` works well for extendability. Similar for Scala with its `extension` keyword.

What is Mojo’s plan for this?

---

<div class="post-metadata">

**Author:** ![HammadHAB](https://avatars.discourse-cdn.com/v4/letter/h/e495f1/32.png) [@HammadHAB](https://forum.modular.com/u/HammadHAB)\
**Post date:** [February 19, 2025, 11:22am UTC](https://forum.modular.com/t/structs-extendability/591/2 "2025-02-19T11:22:48Z")

</div>

I don’t think Mojo supports this yet. Their roadmap says that they’re currently not focusing on syntatic sugar right now.

> **[Mojo🔥 roadmap & sharp edges | Modular](https://docs.modular.com/mojo/roadmap/)**
>
> A summary of our Mojo plans, including upcoming features and things we need to fix.

---

<div class="post-metadata">

**Author:** ![melodyogonna](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/melodyogonna/32/33_2.png) [@melodyogonna](https://forum.modular.com/u/melodyogonna)\
**Post date:** [February 19, 2025, 11:54am UTC](https://forum.modular.com/t/structs-extendability/591/3 "2025-02-19T11:54:55Z")

</div>

Swift-like extension which should enable something like this is on the roadmap [1]. Mojo’s current trait is limited in many ways and is currently blocking a lot of work in the stdlib. It seems some more work needs to be done in the compiler to enable the team to work on improving traits.

1. [Mojo🔥 roadmap & sharp edges | Modular](https://docs.modular.com/mojo/roadmap/#traits-support)

---

<div class="post-metadata">

**Author:** ![jymchng](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@jymchng](https://forum.modular.com/u/jymchng)\
**Post date:** [February 19, 2025, 1:17pm UTC](https://forum.modular.com/t/structs-extendability/591/4 "2025-02-19T13:17:13Z")

</div>

It is not merely a syntatic sugar because there is not even a syntatically possible way currently to implement a local trait for a foreign type.

But I guess something has to give, and I reckon it will be the syntax, and likely to be a new keyword.

---

<div class="post-metadata">

**Author:** ![owenhilyard](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/owenhilyard/32/41_2.png) [@owenhilyard](https://forum.modular.com/u/owenhilyard)\
**Post date:** [February 20, 2025, 1:42am UTC](https://forum.modular.com/t/structs-extendability/591/5 "2025-02-20T01:42:03Z")

</div>

The current ask from external stdlib contibutors is for other type system features, since right now we’re trying to build out the stdlib to have basic common abstractions. The feature you are describing is on the list we gave to Modular, but it’s a few items down due to implementing a trait for a type you don’t own being a rarer usecase since a lot of what is in Mojo right now is fundamental work and the stdlib team at modular + external contributors are able to help with upstreaming sensible abstractions. This will change as Mojo scales up, but for now we want to prioritize things that empower code inside of a single library so that we can build up those core abstractions. This include things like parametric traits, potentially effect generics, and some features needed for C interop like raw unions, layout controls, and a few other things.

---

<div class="post-metadata">

**Author:** ![jymchng](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@jymchng](https://forum.modular.com/u/jymchng)\
**Post date:** [March 1, 2025, 9:58am UTC](https://forum.modular.com/t/structs-extendability/591/6 "2025-03-01T09:58:32Z")

</div>

Hi @owenhilyard

Thank you for your reply.

Actually, I thought about it, the inheritance syntax can still be used for local trait implementation for foreign types and for foreign trait implementation for local types.

Because one can imagine…

for foreign type, local trait:

```mojo

from foreign_lib import ForeignType

struct ForeignType(LocalTrait):

     fn local_trait_method(...):
        <impl details>

```

Similarly for foreign traits, local type, which is already what is present in current Mojo.

If we are willing to treat each `struct` definition block as an implementation block, then will make the syntax coherent I guess?

---

<div class="post-metadata">

**Author:** ![owenhilyard](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/owenhilyard/32/41_2.png) [@owenhilyard](https://forum.modular.com/u/owenhilyard)\
**Post date:** [March 1, 2025, 4:19pm UTC](https://forum.modular.com/t/structs-extendability/591/7 "2025-03-01T16:19:49Z")

</div>

The main issue isn’t adding the syntax. That will take someone who knows the parser well a day or two. The issue is all of the modifications required to the trait resolution logic and the type system, which is much more involved.

It’s like someone asking for an “AGI question and answer endpoint” in a REST API. It doesn’t take that long to stub out the public interface, but the backend is a lot of work.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [August 28, 2025, 4:20pm UTC](https://forum.modular.com/t/structs-extendability/591/8 "2025-08-28T16:20:13Z")

</div>

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