What is the car feature in Rust?

Trying to solve the problem described in the Binding Related Assessment is not satisfied for Sized trait , I found that the following code gives the following error:

trait SizedTrait: Sized { fn me() -> Self; } trait AnotherTrait: Sized { fn another_me() -> Self; } impl AnotherTrait for SizedTrait + Sized { fn another_me() { Self::me() } } 
 error[E0225]: only auto traits can be used as additional traits in a trait object --> src/main.rs:9:36 | 9 | impl AnotherTrait for SizedTrait + Sized { | ^^^^^ non-auto additional trait 

But Rust Book does not mention auto trait at all.

What is an automatic feature in Rust and how does it differ from a non-automatic feature?

+5
source share
1 answer

An autosymbol name is the new name for the hard-named built-in attribute 1 (OIBIT).

This is an unstable function in which a sign is automatically implemented for each type if they do not refuse or do not contain a value that does not implement the sign:

 #![feature(optin_builtin_traits)] auto trait IsCool {} // Everyone knows that `String`s just aren't cool impl !IsCool for String {} struct MyStruct; struct HasAString(String); fn check_cool<C: IsCool>(_: C) {} fn main() { check_cool(42); check_cool(false); check_cool(MyStruct); // the trait bound `std::string::String: IsCool` is not satisfied // check_cool(String::new()); // the trait bound `std::string::String: IsCool` is not satisfied in `HasAString` // check_cool(HasAString(String::new())); } 

Familiar examples include Send and Sync :

 pub unsafe auto trait Send { } pub unsafe auto trait Sync { } 

Additional information is available in the Volatile Book .


1 These features are neither a failure (they are inactive) nor necessarily built-in (user code, using the night way, can use them). Of the 5 words on their behalf, 4 were outright lies.

+6
source

Source: https://habr.com/ru/post/1276295/


All Articles