-
Notifications
You must be signed in to change notification settings - Fork 94
Description
There are currently no standardized naming conventions for constructor methods. For example, consider these methods:
QDate::from_string_enum(string: &QString, format: DateFormat) -> Option<Self>
QDateTime::from_string(string: &QString, format: DateFormat) -> Option<Self>
QTime::from_string_enum(string: &QString, format: DateFormat) -> SelfQDate::from_string_enum and QDateTime::from_string have the same signature, but different names.
QDate::from_string_enum and QTime::from_string_enum have the same name, but different signatures.
Proposal 1: Constructor methods should be the names of each parameter type, prefixed by from_. If they return Option<Self> rather than Self, the name should be suffixed by _opt, which is a common pattern in other crates. So the above would be replaced by:
QDate::from_qstring_dateformat_opt(string: &QString, format: DateFormat) -> Option<Self>
QDateTime::from_qstring_dateformat_opt(string: &QString, format: DateFormat) -> Option<Self>
QTime::from_qstring_dateformat(string: &QString, format: DateFormat) -> SelfProposal 2: Deprecate all the constructor methods and just use From and TryFrom with tuples. So the above would be replaced by:
impl TryFrom<(&QString, DateFormat)> for QDate
impl TryFrom<(&QString, DateFormat)> for QDateTime
impl From<(&QString, DateFormat)> for QTimeProposal 3: Do proposal 1 and the implementations from proposal 2.