- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.6k
 
Closed
Description
Given a struct:
struct Outlink {
    rel: Option<String>,
    context: Context,
    url: Url,                // Url does not implement Default !!!
    redirect_count: usize,
    content_type: Option<String>,
    // ... more members implementing Default
}
I want to be able to:
#[derive(Default)]
struct Outlink {
    rel: Option<String>,
    context: Context,
    #[default_from=EXPRESSION]
    url: Url,
    redirect_count: usize,
    content_type: Option<String>,
    // ... more members implementing Default
}
Where EXPRESSION is any valid expression of type Url, e.g. Url.parse("file:///dummy").unwrap().
This satisfies at least two scenarios:
a) There is no need anymore for trivil constructors, as they can instead be written as:
    let url = ...;
    let outlink = Outlink {
        url .. Outlink::Default()
    }
b) Types that have no intrinsic default value but do have a sensible default value in the context of another type.
Metadata
Metadata
Assignees
Labels
No labels