IssueRaiser

Tracking issue for RFC 3681: Default field values

<!-- homu-ignore:start --> *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/issues/132162)* <!-- homu-ignore:end --> <!-- NOTE: For library features, please use the "Library Tracking Issue" template instead. Thank you for creating a tracking issue! 📜 Tracking issues are for tracking a feature from implementation to stabilisation. Make sure to include the relevant RFC for the feature if it has one. Otherwise provide a short summary of the feature and link any relevant PRs or issues, and remove any sections that are not relevant to the feature. Remember to add team labels to the tracking issue. For a language team feature, this would e.g., be `T-lang`. Such a feature should also be labeled with e.g., `F-my_feature`. This label is used to associate issues (e.g., bugs and design questions) to the feature. --> This is a tracking issue for the RFC "3681" (rust-lang/rfcs#3681). The feature gate for the issue is `#![feature(default_field_values)]`. Allow `struct` definitions to provide default values for individual fields and thereby allowing those to be omitted from initializers. When deriving `Default`, the provided values will then be used. For example: ```rust #[derive(Default)] struct Pet { name: Option<String>, // impl Default for Pet will use Default::default() for name age: i128 = 42, // impl Default for Pet will use the literal 42 for age } let valid = Pet { name: None, .. }; assert_eq!(valid.age, 42); let default = Pet::d

Posted by estebank on Oct 25, 2024, 11:13 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments

github (Sysadmin)

Tracking issue for RFC 3681: Default field values

estebankOct 25, 2024, 11:13 PM

<!-- homu-ignore:start --> *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/issues/132162)* <!-- homu-ignore:end --> <!-- NOTE: For library features, please use the "Library Tracking Issue" template instead. Thank you for creating a tracking issue! 📜 Tracking issues are for tracking a feature from implementation to stabilisation. Make sure to include the relevant RFC for the feature if it has one. Otherwise provide a short summary of the feature and link any relevant PRs or issues, and remove any sections that are not relevant to the feature. Remember to add team labels to the tracking issue. For a language team feature, this would e.g., be `T-lang`. Such a feature should also be labeled with e.g., `F-my_feature`. This label is used to associate issues (e.g., bugs and design questions) to the feature. --> This is a tracking issue for the RFC "3681" (rust-lang/rfcs#3681). The feature gate for the issue is `#![feature(default_field_values)]`. Allow `struct` definitions to provide default values for individual fields and thereby allowing those to be omitted from initializers. When deriving `Default`, the provided values will then be used. For example: ```rust #[derive(Default)] struct Pet { name: Option<String>, // impl Default for Pet will use Default::default() for name age: i128 = 42, // impl Default for Pet will use the literal 42 for age } let valid = Pet { name: None, .. }; assert_eq!(valid.age, 42); let default = Pet::d

Comments (0)

No comments yet. Start the discussion.

Comment on this issue