# 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:** 1

<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 20, 2026, 9:48am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/1 "2026-10-20T09:48:05Z")

</div>

There's been a recent round of posts on named arguments in Rust: Botahamec's [Named and Optional Arguments are Awesome](https://botahamec.dev/named-optional-args), Steve Klabnik's [Arguing about arguments](https://steveklabnik.com/writing/arguing-about-arguments/), and Matthias Endler's [We Have Named Arguments at Home](https://corrode.dev/blog/named-arguments-at-home/). I've taken my original thoughts from 2016 and written up a design that starts from Endler's premise: Rust already has a named, reorderable, defaultable construct, the `struct`. The design removes the ceremony that makes using a struct this way less appealing.

**TL;DR:** it adds two pieces of syntax. `struct { .. }` is an anonymous struct type in parameter position, and `_ { .. }` is a struct literal or pattern whose type is inferred. Then some named argument sugar.

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

crop(&img, _ { width: 200, .. });

```

**Read the full post:**

> **[Anonymous Struct Parameters: The Idea](https://nixpulvis.com/ramblings/2026-10-19-anonymous-struct-parameters)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![kvverti](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kvverti/32/14653_2.png) [@kvverti](https://internals.rust-lang.org/u/kvverti)\
**Post date:** [October 20, 2026, 2:57pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/2 "2026-10-20T14:57:23Z")

</div>

I’m concerned about the ABI implications of this proposal. Structs are often passed as pointers rather than being passed in registers, for example. I think anonymous struct types declared in function item signatures should at least have a special representation that unpacks the fields for the function call ABI (similar to what `rust-call` does for tuples). Perhaps it can even be turned into a general purpose struct representation (`repr(unpacked)`, perhaps?).

Secondarily the semver implications are strange. Default field values are a bit of a footgun because you can still construct them exhaustively. I’m happy with _only_ getting the anonymous struct syntax without default field values, they seem pretty orthogonal.

---

<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 20, 2026, 4:28pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/3 "2026-10-20T16:28:11Z")

</div>

Firstly, thank you for presenting this all so clearly!

Of the things you've presented, I would find `parameter_type_elision` most useful in my existing code - that would clean up a bunch of things where I'm using multiple `struct`s for named parameters already, and it's already useful to have named `struct`s for those parameters. That, on its own, would be a nice improvement for my use cases today (and we have enough parameters in the `struct`s that ABI implications aren't a concern).

---

<div class="post-metadata">

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

</div>

This is indeed the approach that I would prefer to go with, specially because it answers questions around FFI and it is a composition of features that are useful individually, and it still leaves the door open for future purely syntactic sugar, like a method with a single non-`self` anon `struct` argument being callable with `foo.bar { baz, qux: 42, .. }` or `foo.bar(baz, qux: 42, defaulted: _)`.

---

<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:** [October 20, 2026, 7:05pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/5 "2026-10-20T19:05:47Z")

</div>

> [@ekuber](#):
>
> This is indeed the approach that I would prefer to go with, specially because it answers questions around FFI

Also really helps for running things through closures, too!

---

<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 20, 2026, 7:32pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/6 "2026-10-20T19:32:52Z")

</div>

> [@nixpulvis](#):
>
> ```rust
> fn crop(img: &Image, struct {
> width: u32,
> height: Option<u32> = None,
> x: u32 = 0,
> y: u32 = 0,
> }) -> Image { .. }
> 
> crop(&img, _ { width: 200, .. });
> 
> ```

Is this compatible with this?

```rust
let closure = |aggregate: struct { width: u32, height: Option<u32>, x: u32, y: u32 }| crop(img, aggregate);

```

Why or why not?

---

<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 20, 2026, 8:37pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/7 "2026-10-20T20:37:05Z")

</div>

So I do think the initial version of this feature could support anonymous structs in closures like you show here. However, until we decide on how this feature expands into full blown record types (or if it ever does), that type is probably just going to be treated as a completely different struct from the one that `crop` takes. So you'd still have to call it with `crop(img, _ { width, height })`.

I have some preliminary thoughts on record types, but that's a much larger change to Rust than even this, and there's more history to dig through there and case studies in other languages than I'm fully versed in.

---

<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 20, 2026, 11:15pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/8 "2026-10-20T23:15:47Z")

</div>

Thanks, just want it thought about; I have no opinion on what is "right" at the moment, but I have an eye for corner cases 🙂 .

---

<div class="post-metadata">

**Author:** ![tczajka](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tczajka/32/8923_2.png) [@tczajka](https://internals.rust-lang.org/u/tczajka)\
**Post date:** [October 20, 2026, 11:38pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/9 "2026-10-20T23:38:35Z")

</div>

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

```

---

<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 21, 2026, 12:00am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/10 "2026-10-21T00:00:05Z")

</div>

This was actually my original line of thinking back in 2016, but I doubt the broader community will accept it (maybe I'm wrong).

The biggest issue with this in my opinion is definitions:

```rust
fn f { x: i32 } { todo!() } // not too bad
fn g(a: i32) { x: i32 } -> i32 { todo!() } // getting worse
// kinda a mess
fn h(
    a: i32,
    b: i32,
) {
    x: i32,
    y: i32,
} {
    todo!();
}

```

That said, I personally still kinda like it.

Either way, the core idea remains, and this is mostly a discussion of the `named_parameters` sugar.

---

<div class="post-metadata">

**Author:** ![tczajka](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tczajka/32/8923_2.png) [@tczajka](https://internals.rust-lang.org/u/tczajka)\
**Post date:** [October 21, 2026, 12:18am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/11 "2026-10-21T00:18:34Z")

</div>

I'd just disallow mixing positional parameters with named parameters.

Similarly, enum variants don't allow mixing both at the same time:

```rust
enum E {
    A(i32, i32), // OK
    B{x: i32}, // OK
    C(i32, i32){x: i32}, // no, that's not allowed
}
let a = E::A(1, 2); // OK
let b = E::B{x: 3}; // OK
let c = E::C(1, 2){x: 3}; // nope

```

So I think functions with `{}` arguments would naturally extend what we already have for enum constructors.

---

<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 21, 2026, 12:36am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/12 "2026-10-21T00:36:01Z")

</div>

That doesn't address one of the most core use cases for named arguments though. A function which takes some traditional positional arguments and acts like a normal function, but then takes a bunch of defaulted optional named options.

---

<div class="post-metadata">

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

</div>

And then...

```rust
f(1, 2, 3);

// Same thing
f { 0: 1, 1: 2, 2: 3 };

```

---

<div class="post-metadata">

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

</div>

What's the improvement from not passing the arguments as normal ones? Seems that we can somehow pass the anonymous struct parameters to another function as a 'bulk', but if so we have to find out a way to let compiler know whether passing objects is OK.

Even worse, it seems that there's no way to set a default value for such structures.

---

<div class="post-metadata">

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

</div>

> [@nixpulvis](#):
>
> That doesn't address one of the most core use cases for named arguments though. A function which takes some traditional positional arguments and acts like a normal function, but then takes a bunch of defaulted optional named options.

I think that if a function has some named parameters, it might as well name all the parameters. Again, this is similar to what we already have with enums variants.

With this approach, struct enum variant constructors would become regular functions, just like tuple variant constructors are regular functions.

The defaulted values feature is something that might be useful for all structs, not just for function arguments, so the notation should be the same as whatever notation regular structs might use for defaulted values.

---

<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 21, 2026, 8:58am UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/16 "2026-10-21T08:58:57Z")

</div>

Assuming I understand the proposal correctly, the point is that all of this ends up being syntax sugar for things you can write today with a bit of extra work.

So, starting at the bikeshed named arguments syntax, you might write:

```rust
pub fn foo(bar: u32, baz: &str; idx: usize = 0, limit: Option<usize> = None) -> Result<String, Error>
// called as:
{
    let out = foo(42, "fish", idx: 2, ..local_defaults)?;
}

```

This is syntax sugar for an anonymous `struct`:

```rust
pub fn foo(bar: u32, baz: &str, struct { idx: usize = 0, limit: Option<usize> = None}) -> Result<String, Error>
// called as:
{
    let out = foo(42, "fish", _ { idx: 2, ..local_defaults })?;
}

```

And in turn, this is syntax sugar for an existing construct where you have to make up a name:

```rust
#[derive(Default)]
pub struct KeywordParams {
    pub idx: usize,
    pub limit: Option<usize>,
}

pub fn foo(bar: u32, baz: &str, KeywordParams { idx, limit }: KeywordParams) -> Result<String, Error>
// called as:
{
    let out = foo(42, "fish", KeywordParams { idx: 2, ..local_defaults })?;
}

// Or, using the optional `#![feature(parameter_type_elision)]`
pub fn foo(bar: u32, baz: &str, KeywordParams { idx, limit }) -> Result<String, Error>
// The line above is just syntax sugar for the more verbose
// version where `KeywordParams` is repeated

```

Any optimizations to Rust's ABI that improve the final case (which is one that already exists in Rust code) also improve the ABI for the syntax sugar variants that this proposal adds. IMO, that's what makes this proposal a compelling way to handle named and defaulted arguments - it's not creating something new, with new ABI optimizations needed, when it can instead build on something that already exists.

---

<div class="post-metadata">

**Author:** ![RustDev](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rustdev/32/14659_2.png) [@RustDev](https://internals.rust-lang.org/u/RustDev)\
**Post date:** [October 22, 2026, 2:12pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/17 "2026-10-22T14:12:56Z")

</div>

Your suggestion is very beautiful, but there are problems that occur after you work Struct anonymously, which is difficult to determine the name of the values and their places for the user who does not know. What did I do, but my suggestion is to make Struct clear to the user, to the programmers, and developers, to tell you about the values, their arrangement, shape, names and number, and this makes programming easier and better, and even at the time of using it, all you have to do is added inside impl, the things that you want, such as new, and it takes care of putting the values, but if you want to change one value, for example, you can make functions to do that and save you and we have to work

```rust

#[derive(inFn)]
struct haql {
    width: u32,
    height: Option<u32> = None,
    x: u32 = 0,               
    y: u32 = 0,            
} 
impl haql {
 fn new (…){…}
…
}

fn crop ( img : &Image , haql){…}

crop (..,haql::new());

 

```

---

<div class="post-metadata">

**Author:** ![HjVT](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hjvt/32/10365_2.png) [@HjVT](https://internals.rust-lang.org/u/HjVT)\
**Post date:** [October 22, 2026, 11:03pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/18 "2026-10-22T23:03:12Z")

</div>

This is actually what I feel like would make most sense as well, and it could help in the argument-pass-through case, if we could name that type via an assoc type on `Fn*` traits.

---

<div class="post-metadata">

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

</div>

You can _almost_ get there on nightly, but by making the struct callable:

```rust
#![feature(unboxed_closures)]
#![feature(fn_traits)]

struct Image;

#[derive(Debug, Default)]
#[allow(unused, non_camel_case_types)]
struct crop {
    width: u32,
    height: Option<u32>,
}

impl std::ops::FnOnce<()> for crop {
    type Output = Image;
    extern "rust-call" fn call_once(self, _args: ()) -> Image {
        dbg!(self);
        Image
    }
}

fn main() {
    crop{ width: 200, height: None}();
}

```

Optional arguments are possible too but using `default` is currently more verbose:

```rust
#[allow(non_upper_case_globals)]
const crop: crop = crop { width: 0, height: None };

crop{ width: 200, ..crop}();

```

And now that I write that out it does look very repetitious.

---

<div class="post-metadata">

**Author:** ![eugene2k](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/eugene2k/32/3525_2.png) [@eugene2k](https://internals.rust-lang.org/u/eugene2k)\
**Post date:** [October 23, 2026, 3:51pm UTC](https://internals.rust-lang.org/t/named-arguments-are-just-structs-anonymous-struct-parameters/24683/20 "2026-10-23T15:51:43Z")

</div>

This post was flagged by the community and is temporarily hidden.

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