# Named Arguments are Just Structs: Anonymous Struct Parameters

**URL:** <https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683>\
**Category:** language design\
**Created:** [October 20, 2026, 9:48am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683 "2026-10-20T09:48:05Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![EDEADLINK](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/edeadlink/32/14668_2.png) [@EDEADLINK](https://internals.rust-lang.org/u/EDEADLINK)\
**Post date:** [October 24, 2026, 3:52am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/21 "2026-10-24T03:52:19Z")

</div>

> [@chrisd](#):
>
> `crop{ width: 200, height: None}();`

This is also still clearly a function call unlike

> [@tczajka](#):
>
> ```rust
> f{a: 1, b: 2, c: 3}; // struct function
> 
> ```

which makes it much less problematic to teach and retrofit into the language.

When you add positional arguments to that, they have to come last at the callsite, but with just anonymous struct definitions we can do:

```rust
#[named_arguments::named_arguments]
pub fn crop(count: u32, { width: 200, height: None, .. }) {...}

fn main() 
{
    crop{width, height, ..}(3); 
}

```

This means the named arguments MVP doesn't need to include struct literal inference, but it would be a nice to have.

like the idea of using `..` in the anonymous functions struct to imply `#[must_default_construct]` or whatever we decide to call the attributes for a non\_exhaustive structs that can and must be defaulted.

---

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [October 24, 2026, 10:02am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/22 "2026-10-24T10:02:08Z")

</div>

> [@tczajka](#):
>
> Named arguments are just structs, and unnamed arguments are just tuples. Just like we have tuple-variants and struct-variants of enums, we could by analogy have tuple-functions and struct-functions:
> 
> ```rust
> f(1, 2, 3); // tuple function
> f{a: 1, b: 2, c: 3}; // struct function
> 
> ```

That would be very neat, but I think it's too late to allow `name { ... }` to have arbitrary side-effects -- there are probably already macros relying on this. Putting brace structs into the value namespace will also break tons of stuff.

This is on my list of Rust 1.0 "if I had a time machine" regrets.

---

<div class="post-metadata">

**Author:** ![nixpulvis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nixpulvis/32/1233_2.png) [@nixpulvis](https://internals.rust-lang.org/u/nixpulvis)\
**Post date:** [October 24, 2026, 12:27pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/23 "2026-10-24T12:27:45Z")

</div>

Yea, if only... but I tend to agree, which is why I pivoted from the idea I started with a decade ago (time flying!) and landed here.

---

<div class="post-metadata">

**Author:** ![danjl1100](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/danjl1100/32/6466_2.png) [@danjl1100](https://internals.rust-lang.org/u/danjl1100)\
**Post date:** [October 25, 2026, 3:21am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/24 "2026-10-25T03:21:13Z")

</div>

I really like the piecewise approach here, reaching the final goal with several widely-applicable features.

For elided struct patterns, it seems there's a conceptual collision between [`mut_restrictions`](https://doc.rust-lang.org/unstable-book/language-features/mut-restriction.html) on fields and mutable bindings. I assume anonymous structs are so short lived that there's no need for restrictions in the elided struct syntax, just pointing out a question that others may have.

The elided parameter types section seems very useful, though there does seem to be an asymmetry of pattern vs type when combining them. For non-`Copy` types the `&` in the pattern `&Point { .. }` no longer "undoes" a ref in this condensed form.  
The post states that the condensed form short for #2 below, but is it possible to specify #1 as well?

1. `fn f(Point { x, y }: &Point)`
2. `fn f(&Point { x, y }: &Point)`

More specifically for an externally defined non-`Copy` struct:  
`struct Person { age: u32, name: String }`  
If you're passing `&Person` with elided parameter types, to avoid a compile error for moving out of `name` would you be forced to use `&Person { ref name, age }: &Person` instead of the (newer?) match ergonomics version `Person { name, age }: &Person`?

---

<div class="post-metadata">

**Author:** ![nixpulvis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nixpulvis/32/1233_2.png) [@nixpulvis](https://internals.rust-lang.org/u/nixpulvis)\
**Post date:** [October 25, 2026, 4:47am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/25 "2026-10-25T04:47:53Z")

</div>

Thanks for the thoughtful reply.

> [@danjl1100](#):
>
> For elided struct patterns, it seems there's a conceptual collision between [`mut_restrictions`](https://doc.rust-lang.org/unstable-book/language-features/mut-restriction.html) on fields and mutable bindings. I assume anonymous structs are so short lived that there's no need for restrictions in the elided struct syntax, just pointing out a question that others may have.

Not going to lie, I didn't even know about that line of work. My gut reaction is that anonymous structs simply don't get `mut_restrictions`, since I wasn't planning on providing a way to `impl <anon struct>` so the API is very much limited to what you can do with the fields directly. The anonymous struct is tied to its function, so it gets its visibility and restrictions to follow, because if you made something like this:

```rust
pub fn foo(struct { mut(crate) x: u32 }) {}

```

You would have no way to call it in `foo`'s `pub` context, since:

> Further, a`struct`, `union`, or `enum` variant containing fields with an associated `MutRestriction` may not be constructed with `struct` expressions unless all fields are unrestricted in the present scope

Technically, right now I don't think they collide since there's no bare `mut` restriction AFAICT, but it's left open:

> - `impl` and `mut` could be usable without a path if deemed necessary. This behavior would be identical to omitting the keyword entirely.

So I agree, this is bumping up against that a bit, and while it might not technically conflict, it's a bit awkward. I also would like to leave the door open for future work on more generalized record types if that ever moves forward, and then the argument might not be an anonymous struct tied directly to the function anymore.

Needs deeper thought I feel, but I don't feel it'll be impossible to overcome, since this is really just a question of how to address the pattern elision in function definitions I think.

* * *

> [@danjl1100](#):
>
> If you're passing `&Person` with elided parameter types, to avoid a compile error for moving out of `name` would you be forced to use `&Person { ref name, age }: &Person` instead of the (newer?) match ergonomics version `Person { name, age }: &Person`?

Both `&Person { ref name, age }: &Person` and `Person { name, age }: &Person` would still work as they do today, since you're not eliding anything, but you could also now write:

```rust
fn foo(&Person { ref name, age })

```

Which is literally just sugar for the same `&Person { ref name, age }: &Person`. However, `Person { name, age }: &Person` simply cannot be elided since the pattern and the type are different.

---

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [October 25, 2026, 11:48am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/26 "2026-10-25T11:48:44Z")

</div>

I like this approach but it has some issues that I think are solvable. One of the important properties of default paratmeters is that you can add more parameters later without breaking existing code. So requiring an additional parameter that will be just `_{}` is still problematic if the function didn't have it to begin with.

This can be solved by introducing `pub trait ImplicitDefault: Default {}` which makes the compiler call `default()` to obtain the value of last parameter of a function call if explicit one isn't passed. Additionally, it seems the anonymous struct should be generated as `#[non_exhaustive]`, to force people use the `..` syntax. Or perhaps, allow creating the struct even when it's missing by filling in the parameters. I suspect this can be again made into a trait using custom field projections.

---

<div class="post-metadata">

**Author:** ![robinm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/robinm/32/6255_2.png) [@robinm](https://internals.rust-lang.org/u/robinm)\
**Post date:** [October 26, 2026, 11:46am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/27 "2026-10-26T11:46:04Z")

</div>

Can we do a crater run to check this?

EDIT: or a least have `foo{named, arguments}` in the next edition (and `foo(_{named, arguments})` for all the previous editions)?

---

<div class="post-metadata">

**Author:** ![robinm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/robinm/32/6255_2.png) [@robinm](https://internals.rust-lang.org/u/robinm)\
**Post date:** [October 26, 2026, 11:51am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/28 "2026-10-26T11:51:51Z")

</div>

Regarding `#[non_exhaustive]`, if you write `struct{ foo: i32 = 3}`, it's not (so can but doesn't have to be constructed with `..`), and `struct{ foo: i32 = 3, ..}`, would be (so must be constructed with trailing `..`).

---

<div class="post-metadata">

**Author:** ![Soreg404](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@Soreg404](https://internals.rust-lang.org/u/Soreg404)\
**Post date:** [October 30, 2026, 5:14pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/29 "2026-10-30T17:14:54Z")

</div>

I may not be exactly in the loop here, excuse me,

but if it gets to the point where the user considers _optional arguments_ I'd very much opt for a **builder struct**.

Someone here probably suggested this already so I'm adding my voice for that

---

<div class="post-metadata">

**Author:** ![nixpulvis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nixpulvis/32/1233_2.png) [@nixpulvis](https://internals.rust-lang.org/u/nixpulvis)\
**Post date:** [October 30, 2026, 6:59pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/30 "2026-10-30T18:59:16Z")

</div>

Without getting into a long debate about when to use named parameters vs builder patterns... first just how did you feel about the `std::fs::copy` example?

> **[Unambiguous calls - Anonymous Struct Parameters: The Idea](https://nixpulvis.com/ramblings/2026-10-19-anonymous-struct-parameters#unambiguous-calls)**
>
> There have been a few recent posts on how Rust should adopt named arguments, and I even had some thoughts on the matter back in a comment I left on the issue in 2016. My original idea was never really something I expected to be adopted, but my point...

Builder patterns are great, especially when you need to do runtime logic in the calls, but they are heavier and named arguments are nice too IMO.

Does this mean you now have more options for how you want to represent your API, yes. Does that mean the ecosystem will have some people preferring one and other people preferring the other, yes. I don't view that as a problem here. I want to reduce friction to making clear APIs.

---

<div class="post-metadata">

**Author:** ![farnz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/farnz/32/6587_2.png) [@farnz](https://internals.rust-lang.org/u/farnz)\
**Post date:** [October 30, 2026, 7:41pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/31 "2026-10-30T19:41:58Z")

</div>

Bear in mind that the `..` syntax for optional arguments is "just" [default field values](https://doc.rust-lang.org/unstable-book/language-features/default-field-values.html) - it's not special "optional argument" syntax.

That's the beauty of this specific proposal - there's very little that's special-cased because it's a function call, and what special cases there are about removing boilerplate that passing and destructuring a struct as an argument brings in.

To put that concretely,

```rust
fn crop(
    img: &Image;
    width: u32,
    height: Option<u32> = None,
    x: u32 = 0,
    y: u32 = 0,
) -> Image {
    …
}

crop(&img, width: 200, ..);

```

is a stack of sugar for:

```rust
struct CropParameters {
    width: u32,
    height: Option<u32> = None,
    x: u32 = 0,
    y: u32 = 0,
}

fn crop(
    img: &Image;
    CropParameters {
        width,
        height,
        x,
        y,
    }: CropParameters
} -> Image {
    …
}
crop(&img, CropParameters { width: 200, .. });

```

The only thing that's truly new about this syntax is the ability for the struct to be unnamed and unnameable.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 31, 2026, 1:14am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/32 "2026-10-31T01:14:59Z")

</div>

> [@farnz](#):
>
> ```rust
> struct CropParameters {
> width: u32,
> height: Option<u32> = None,
> x: u32 = 0,
> y: u32 = 0,
> }
> 
> ```

This looks new to me. Or is this just a shortcut for `#[derive(Default)]` and `#[default = …]` attributes? The latter of which might not exist either given that it's only documented to specify the default variant for `enum`s.

---

<div class="post-metadata">

**Author:** ![nixpulvis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nixpulvis/32/1233_2.png) [@nixpulvis](https://internals.rust-lang.org/u/nixpulvis)\
**Post date:** [October 31, 2026, 1:22am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/33 "2026-10-31T01:22:16Z")

</div>

Please actually at least read the first paragraph of the post. It mentions the merged RFC 3681.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [October 31, 2026, 1:30am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/34 "2026-10-31T01:30:14Z")

</div>

Oh neat, I missed that one. Thanks!

---

<div class="post-metadata">

**Author:** ![Soreg404](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@Soreg404](https://internals.rust-lang.org/u/Soreg404)\
**Post date:** [November 1, 2026, 8:32am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/35 "2026-11-01T08:32:58Z")

</div>

About the example with `std::fs::copy`, an idea would be to differentiate types for an `InPath` and `OutPath` then it would be an explicit compile error to write `copy(b, a)` if b is an `OutPath`

You could do that, I think, by:

```rust
type OutPath = Path;
type InPath = Path;
fn copy(from: InPath, to: OutPath);

let a = &InPath::new("/some/dir/some/file");
let b = &OutPath::new("/other/file");

// copy(b, a) // Error: invalid type
copy(a, b)

```

(not testing now, but should work like that?)

This kinda goes off track of an annonymous struct, sorry.  
But I feel that "anonymous struct" is kinda a "nuke solution"  
But I refrain from opinionating atm

Actually, `InPath` and `OutPath` are a flimsy solution, but am just proposing alternatives

* * *

edit:  
Also, in that example with `copy`, one could write both ways

```rust
copy(_ { from: a, to: b })?;
// and
copy(_ { to: b, from: a })?;

```

which may introduce mess

---

<div class="post-metadata">

**Author:** ![nixpulvis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nixpulvis/32/1233_2.png) [@nixpulvis](https://internals.rust-lang.org/u/nixpulvis)\
**Post date:** [November 2, 2026, 10:35am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/36 "2026-11-02T10:35:04Z")

</div>

> [@Soreg404](#):
>
> ```rust
> type OutPath = Path;
> type InPath = Path;
> 
> ```

What you're describing is the [New Type Idiom](https://doc.rust-lang.org/rust-by-example/generics/new_types.html), which would require `struct OutPath(Path)` to declare a new type. Your `InPath` and `OutPath` are interchangeable still.

Yes, newtypes can absolutely allow an API designer to avoid ambiguity as well, but the caller now has to do some wrapping to call it. You could argue that the anonymous struct is a form of wrapping too I suppose, but it's less boilerplate and fewer needed public items to manage.

> [@Soreg404](#):
>
> ```rust
> copy(_ { from: a, to: b })?;
> // and
> copy(_ { to: b, from: a })?;
> 
> ```

I really don't understand some people's issue with reorderable fields of structs, but I've heard this before. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [November 2, 2026, 8:07pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/37 "2026-11-02T20:07:18Z")

</div>

> [@Soreg404](#):
>
> Also, in that example with `copy`, one could write both ways
> 
> ```rust
> copy(_ { from: a, to: b })?;
> // and
> copy(_ { to: b, from: a })?;
> 
> ```
> 
> which may introduce mess

This is 100% by design for anything nominal, IMHO. Just like you can construct or destruct a `struct` in whichever order you like best.

Also, you'll notice that pointers now have `copy_to` and `copy_from` methods, so I don't think that "must strictly be done in one prescribed order" really fits with how Rust tends to work overall.

---

<div class="post-metadata">

**Author:** ![Soreg404](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@Soreg404](https://internals.rust-lang.org/u/Soreg404)\
**Post date:** [November 3, 2026, 8:38am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/38 "2026-11-03T08:38:08Z")

</div>

I stand corrected about the new type idioms and their usage in APIs

Order in structs creation / destructuring is what I would like to have, how to say it, more control of? just to have "nicely aligned code" or something I can't express. Maybe more lints for that, but not sure.

imagine:

```rust
copy(_ { from: a, to: b })
copy(_ { from: c, to: d })
...
copy(_ { to: f, from: e })

```

irks a bit, but that's just my whining atp

---

<div class="post-metadata">

**Author:** ![Ddystopia](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ddystopia/32/10915_2.png) [@Ddystopia](https://internals.rust-lang.org/u/Ddystopia)\
**Post date:** [November 3, 2026, 10:50am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/39 "2026-11-03T10:50:47Z")

</div>

I'm getting a very strong C++ vine from this, especially from `()` and `{}` initializers 😅

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [November 5, 2026, 6:06pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/40 "2026-11-05T18:06:29Z")

</div>

> [@Soreg404](#):
>
> Maybe more lints for that, but not sure.

This is generally the kind of thing that we'd definitely do with a lint not with a hard error, yes. (Without saying whether this specific case _should_ be linted.)

My personal heuristic is that if it'd be harder to write the rejection rule into the spec than to just define what it "obviously" does, then it should be at most a lint. And that's clearly the case for the struct initializers: what it's spec'd to do is obvious no matter the order of field names.

Maybe there's a case for a lint about local inconsistency, but also locally there's presumably a reason that the person put them in the order they did. If it's not more likely that it was accidental than intentional, linting might not be worth doing either.

[Previous page](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683.md?page=1)

[Next page](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683.md?page=3)
