rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Add ide-assist, generate single field struct From

Open A4-Tacks opened this issue 7 months ago • 1 comments

Close rust-lang/rust-analyzer#19696

Assist: generate_single_field_struct_from

Implement From for a single field structure, ignore trivial types.

# //- minicore: from, phantom_data
use core::marker::PhantomData;
struct $0Foo<T> {
    id: i32,
    _phantom_data: PhantomData<T>,
}

->

use core::marker::PhantomData;
struct Foo<T> {
    id: i32,
    _phantom_data: PhantomData<T>,
}

impl<T> From<i32> for Foo<T> {
    fn from(id: i32) -> Self {
        Self { id, _phantom_data: PhantomData }
    }
}

A4-Tacks avatar May 12 '25 10:05 A4-Tacks

r? @Veykril

A4-Tacks avatar May 26 '25 11:05 A4-Tacks

@ShoyuVanilla Can merge this pr?

A4-Tacks avatar Jul 17 '25 23:07 A4-Tacks

I forgot about this as I didn't have merge permission then 😅

ShoyuVanilla avatar Jul 18 '25 01:07 ShoyuVanilla