rust - Why is `Into` not Send/Sync? -


from line:

fn b<a>(a: a, b: copy + into<a>) {} 

i'm getting error non-send/sync additional trait, pointing into<b> bit. if remove it, compiles. if change definition take additional type parameter satisfies both traits, compiles.

fn a<a, b: copy + into<a>>(a: a, b: b) {} 

note full error message this:

error[e0225]: send/sync traits can used additional traits in trait object  --> src/main.rs:1:25   | 1 | fn b<a>(a: a, b: copy + into<a>) {}   |                         ^^^^^^^ non-send/sync additional trait 

this error message not making statement whether into<a> implements send or sync; saying trait into<a> itself not either of traits.

the compiler telling because compiler assuming deliberately attempting create trait object multiple traits.

  • typical examples of trait objects things box<trait> or &trait. happen have written code without indirection before trait itself, not supported (at least not in rust today), compiler treating code if type declaration b: copy + into<a> is trait object, , finding problems arise after making such assumption.

  • you can read more trait objects in the book

  • if write code 1 trait in trait object, e.g. b: std::fmt::debug, compiler give different error:

    error[e0277]: trait bound `std::fmt::debug + 'static: std::marker::sized` not satisfied  --> src/main.rs:1:15   | 1 | fn b<a>(a: a, b: std::fmt::debug) {}   |               ^ `std::fmt::debug + 'static` not have constant size known @ compile-time   |   = help: trait `std::marker::sized` not implemented `std::fmt::debug + 'static`   = note: local variables must have statically known size 

anyway, in rust today, cannot put multiple traits single "trait object". there 1 exceptional case: can use send and/or sync additional traits in trait object.

so compiler telling attempt use into<a> additional trait in trait object invalid, because can have send or sync additional trait, , into<a> not either of those.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -