Skip to content

Tracking Issue for mem_reshape #130848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 3 tasks
hazelwiss opened this issue Sep 25, 2024 · 1 comment
Open
1 of 3 tasks

Tracking Issue for mem_reshape #130848

hazelwiss opened this issue Sep 25, 2024 · 1 comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@hazelwiss
Copy link

hazelwiss commented Sep 25, 2024

Feature gate: #![feature(mem_reshape)]

This is a tracking issue for core::mem::reshape.

core::mem::reshape allows modifying a mutable reference with its moved underlying value.

Public API

// core::mem

let mut x = "some_string".to_string();
reshape(&mut x, |x|  x + " that is reshaped");

println!("{x}");

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@hazelwiss hazelwiss added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 25, 2024
@workingjubilee
Copy link
Member

The example is poorly-motivated because it is easily done using AddAssign:

fn mut_ref_boundary(s: &mut String) {
    *s += " that is reshaped";
}

let mut x = "some_string".to_string();
mut_ref_boundary(&mut x);

println!("{x}");

The cases where we need this function, also called replace_with, are somewhat complex. If we were to add it, we would need a similarly somewhat complex example, or else we would not be able to explain what it is actually needed for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants