IDEA: Instead of lifetimes, why not use input-output dependency?

⚓ Rust    📅 2025-09-07    👤 surdeus    👁️ 2      

surdeus

I am new to Discourse posting. I tried to post in https://internals.rust-lang.org/

I edit the post in a Markdown editing software and then copy it to the browser editor. It silenced me for fast typing. So, sorry for posting this here again.

I am new to all of this.

I am a beginner in Rust. So, I have a doubt.

Instead of using lifetimes, why not the functions denote which outputs depend on which inputs.

Currently, this is how Rust works.

fn longest<'a>(s1: &'a str, s2: &'a str) -> &'a str {
    if s1.len() > s2.len() {
        s1
    } else {
        s2
    }
}

Instead of the above, what about the following.

fn longest(s1: &str, s2: &str) -> &str 
return depends_on s1 & s2
{
    if s1.len() > s2.len() {
        s1
    } else {
        s2
    }
}

This need not be the exact syntax. But what about something similar to this, instead of lifetimes.

If there are multiple return values, then give names to each return value in the signature, but it does not need to create a variable like in Go-lang.

Example:

fn shortest_and_longest(s1: &str, s2: &str) -> (shortest: &str, longest: &str)
shortest depends_on s1 & s2,
longest depends_on s1 & s2,
{
    ...
}

Is there any technical reasons for not using this syntax. Am I missing something?

I would be extremely glad if someone can explain the technical details behind it.

1 post - 1 participant

Read full topic

🏷️ Rust_feed