Skip to content

Sort items in rustdoc with integers in their names more naturally #39596

Closed

Description

@clarfonthey

Right now, Trait10 will be shown before Trait2 in rustdoc. It'd be nice if this could be changed to sort numbers in order by value whenever they're encountered.

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Feb 7, 2017
  2. phungleson commented on Feb 11, 2017

    @phungleson
    Contributor

    Hey guys, wanted to help with this, but this is the first time i look into rustdoc, any suggestion where i can start?

  3. clarfonthey commented on Feb 11, 2017

    @clarfonthey
    ContributorAuthor

    When I took a look myself, it was just a call to slice::sort that did the sorting, so, if you make a slice sorting function that works and give it a few tests, someone should be able to point you to the place to call it.

  4. phungleson commented on Feb 11, 2017

    @phungleson
    Contributor

    Thanks @clarcharr any place in the code you can put here?

    I tried to search the whole project for Trait10 Trait2 and slice::sort but couldn't find anything.

  5. keeperofdakeys commented on Feb 12, 2017

    @keeperofdakeys
    Contributor
  6. phungleson commented on Feb 12, 2017

    @phungleson
    Contributor

    Yep thanks @keeperofdakeys looks like so, i will try to make changes around it.

    Thanks again ;)

  7. clarfonthey commented on Feb 20, 2017

    @clarfonthey
    ContributorAuthor

    So, I found out a relatively easy way to do this type of sorting and decided to make a crate for it, which I've called version-sort. I'm not sure how we'd add this type of functionality to rustdoc specifically, but I figured that I'd mention that I have created the code that would do this sort of sorting. (heh)

  8. phungleson commented on Feb 20, 2017

    @phungleson
    Contributor

    Hehe I think this functionality can be used for more than just in version number, but file name etc.., not sure how to call it though

  9. Boddlnagg commented on Feb 20, 2017

    @Boddlnagg
    Contributor

    This is known as "natural sort order", and there are at least two crates for this, though I don't know about their quality.

  10. ranma42 commented on Feb 20, 2017

    @ranma42
    Contributor

    Notice that although for human-written code the suggested order would in general be better, it might be a regression if the "number" is not decimal (which might happen for example for machine-generated types) as T000 T010 T0A0 T110 would then not be considered sorted.

  11. clarfonthey commented on Feb 20, 2017

    @clarfonthey
    ContributorAuthor

    @ranma42 Check out the crate I linked; I specifically track leading zeroes so that 001 comes before 01, before 1, before 10.

  12. clarfonthey commented on Feb 20, 2017

    @clarfonthey
    ContributorAuthor

    Floating point strings don't sort by value (i.e. 2.2 < 2.10) which is why I'd consider this a version sort, not a numerical sort. For rustdoc this doesn't matter either way because periods can't be in identifiers.

  13. ranma42 commented on Feb 20, 2017

    @ranma42
    Contributor

    @clarcharr The issue is not with leading zeros, but with non-digit characters. For example, would T100 sort before T1A0? (if you interpret the numbers in hexadecimal, i.e. as 0x100 and 0x1A0, this is the obvious sorting, but if you split at every non-digit, then it is not).

    EDIT: oops, I changed the example. in the original one, would T010 be sorted before T0A0?

  14. clarfonthey commented on Feb 21, 2017

    @clarfonthey
    ContributorAuthor

    Digits come before letters lexically, so, that'd still work as expected. Although I think that automatically coercing a-f as numbers has the ability for too many false positives.

    For example, "String1" < "StringArgument" < "String10" just doesn't make any sense.

  15. 7 remaining items

  16. added a commit that references this issue on Mar 24, 2017
  17. GuillaumeGomez commented on Apr 14, 2017

    @GuillaumeGomez
    Member

    Seems this issue has been fixed. Closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions