Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upWhere do we want to use associated consts? #1135
Comments
This comment has been minimized.
|
|
This comment has been minimized.
|
Is anyone presently working on this? If not, I'd like to volunteer to give this a try. |
This comment has been minimized.
|
I don't think anyone is working on it so feel free to work on it. |
Eijebong
added
the
assigned
label
Sep 4, 2017
sgrif
closed this
Sep 5, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
killercup commentedAug 31, 2017
Rust 1.20 stabilized associated consts!
…and, in contrast to every other
hipsterunstable Rust feature under the sun, we apparently have neither code comments nor commit messages in diesel's code base telling us what places could benefit from this new feature. But not to worry, we can easily[^1] find some!Wait—should we? It makes the API a bit more idiomatic at the cost of requiring at least 1.12 to build diesel. Additionally, we could declare the current methods as
#[deprecated]and not break any builds. The constants should be inSCREAMING_SNAKE_CASEanyway, so the names won't conflict. I'd say: Go for it, and actually replace these static methods. Right now, before 1.0, we can afford these breaking changes, after that we need to live with the status quo.Here are the places[^1] that I found that could benefit from associated consts:
diesel::query_builder::QueryId:const HAS_STATIC_QUERY_ID: boolinstead offn has_static_query_id() ->booldiesel::query_source::Column:const NAME: &'static strinstead offn name() -> &'static strdiesel::types::FromSqlRow:const FIELDS_NEEDED: usize(with default) instead offn fields_needed() -> usize { ... }I'm not entirely sure if we want/can/should turn methods like
foo() -> Self::Foointo associated consts. This would add a few more cases (<Foo as diesel::associations::HasTable>::table(),<Foo as diesel::query_source::Table>::all_columns(), and<Foo as diesel::associations::BelongsTo>::foreign_key_column()).[^1]:
rg -i ' (pub | ) fn (.*?)\(\) ->'