Lifetime parameter default value


Rust does not have default value for lifetime parameters:

struct MyMessage<'a = 'static> { ... } // parse error

Any reason why rust has no such thing? (I guess it could interfere with lifetime elision, but I don’t know how).

My use case is this: I want to define cow-like structs, which will be used as owned most of the time. So even if structs are used as owned, users have to always mention 'static lifetime all the time, e. g.

fn make_me_message() -> MyMessage<'static> { ... }

with default lifetimes it could be written as:

fn make_me_message() -> MyMessage { ... }

The issue can be resolved by having type alias:

type MyMessage = MyMessageCow<'static>;

but it is not very elegant IMHO.


closed #2

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.