# Thoughts on tuples

**URL:** <https://internals.rust-lang.org/t/thoughts-on-tuples/18778>\
**Category:** language design\
**Created:** [May 3, 2023, 4:25pm UTC](https://internals.rust-lang.org/t/thoughts-on-tuples/18778 "2023-05-03T16:25:44Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![Massou](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/massou/32/10103_2.png) [@Massou](https://internals.rust-lang.org/u/Massou)\
**Post date:** [June 4, 2023, 10:09am UTC](https://internals.rust-lang.org/t/thoughts-on-tuples/18778/21 "2023-06-04T10:09:49Z")

</div>

The problem with this is the memory layout where the tuple slice/sub tuple may not have the same memory layout as it's parent so creating a new tuple may not be what's wanted here.

I think that it can be solved by marking which tuple element/offset remains accessible through a variable. Not sure if such metadata can exist in the compiler (if it's possible I definetely will write an rfc).

If marking which offsets/members are accessible/not accessible (by move/ref/mut) this can also work with structs

Pseudo code to illustrate this

```rust
fn takes_refs(string: &mut String, nb: &mut i32);
fn takes_tuple(t: (&mut String, &mut i32));

let (_, rest @ .., _) = &mut (1, String::new("hello"), 12, 13);

takes_refs(rest); // rest is an alias to a mutable string and a mutable i32
takes_tuple((..rest)); // tuple created with members of rest

// only 2 fields of the original tuple can be used by rest
let (a, b): (&mut String, &mut i32) = rest;
// or
let { 0: a, 1: b } = rest;

```

Similar functionality for structs, member names can be used (this could be an evolution after full tuple bindings)

```rust
struct Foo { field1: u8, field2: u8, field3: String }
struct Bar<'a> { field2: &'a u8, field3: &'a String }

fn takes_refs(field2: &u8, field3: &String);
fn takes_bar<'a>(bar: Bar<'a>);

let Foo {_field1, rest.. } = &Foo { ... };
takes_refs(rest);
takes_bar(Bar{..rest})
// only field2 and field3 are marked as accessible through rest
let { field2, field3 } = rest;

```

---

_[View the full topic](https://internals.rust-lang.org/t/thoughts-on-tuples/18778)._
