Skip to content

Suggestion: Add a compiler indication for "get the same type that that variable has" #3241

@blyxyas

Description

@blyxyas

What I mean is (for example) add a t# before a variable to get that type, instead of using a function that slows performance, the compiler gets the same type of that variable.

Example

Example of how this may work.

fn translate(input: String) -> Vec< t# ram > {
    
    let mut ram: Vec<u32> = Vec::new();
    let mut result: Vec< t# ram > = Vec::new(); /*
This improves readability, we can see at first glance that this Vec is made up of various "ram" types */
    
    let mut sum: u32 = 0;

    for phrase in vec {

        for word in phrase.split_whitespace() {

            for c in word.chars() {
                sum += multiplier * c as u32;
            }

            ram.push(sum);
            sum = 0;

        }

        result.push(ram.clone());
        ram.clear();

    }

    return result;
}

This is just a quick example I made up from a real code I'm using, but it would be really useful if the first thing you could see is the same type that another without using the type keyword for only two variables.

This addition could improve readability without losing performance, because it just adds a little bit of time at compile time.
Thanks for reading, that is my suggestion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions