Skip to content

Dynamically sized type parameter syntax #357

@ftxqxd

Description

@ftxqxd

The current syntax for denoting a dynamically-sized type parameter is Sized? T. This acts as a way of removing the implicit Sized bound that all type parameters have by default. This has the nice advantage of being open to adding other default trait bounds in the future with a similar syntax for opting out. (Drop could be one: uninitialised pointers are not able to be dropped, but everything else is.) However, to me it seems inconsistent with the syntax for normal bounds, which come after the type parameter name. It also can’t be used in a where clause, unlike everything else applied to type parameters. Because DST never went through a proper RFC, and the syntax for DSTs has changed twice, it would be nice if we could get some proper feedback on want the syntax should actually be. I personally prefer T: Sized?, but perhaps other people will have other ideas.

For the record, here are the different syntaxes we’ve gone through:

  • unsized T: the original, obvious syntax
  • type T: there was a blog post on this
    • Motivation: Sized ∪ Unsized = All types
  • Sized? T: the current syntax
    • Motivation: Makes the implicit Sized bound normally present in all type parameters optional

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions