What's the difference between `` and `where T: Trait`?

后端 未结 2 578
别那么骄傲
别那么骄傲 2020-12-09 20:43

In the docs for the Send trait, I see both

impl Send for LinkedList 
where
    T: Send, 

and



        
2条回答
  •  离开以前
    2020-12-09 21:10

    The where clause documentation now includes the example:

    When specifying generic types and bounds separately is clearer:

    impl  MyTrait for YourType {}
    
    // Expressing bounds with a `where` clause
    impl  MyTrait for YourType where
        A: TraitB + TraitC,
        D: TraitE + TraitF {}
    

    shepmaster mentions:

    My personal style is to always use the where form.
    Having a single shape that is also easier to git diff when adding new bounds is worth the extra line of code for me.

    I agree, considering Git 2.23 (Q3 2019) will add rust to its funcname and words boundaries.

    See commit 33be7b3 (30 May 2019) by Johannes Sixt (j6t).
    See commit d74e786 (16 May 2019) by Marc-André Lureau (``).
    (Merged by Junio C Hamano -- gitster -- in commit a41dad4, 21 Jun 2019)

    userdiff: add built-in pattern for rust

    This adds xfuncname and word_regex patterns for Rust, a quite popular programming language.
    It also includes test cases for the xfuncname regex (t4018) and updated documentation.

提交回复
热议问题