unstable book: OIBIT

This commit is contained in:
tinaun 2017-10-10 04:20:49 -04:00
parent 692b94ae25
commit 7735f59e80

View file

@ -0,0 +1,49 @@
# `optin_builtin_traits`
The tracking issue for this feature is [#13231]
[#13231]: https://github.com/rust-lang/rust/issues/13231
----
The `optin_builtin_traits` feature gate allows you to define _auto traits_.
Auto traits, like [`Send`] or [`Sync`] in the standard library, are marker traits
that are automatically implemented for every type, unless the type, or a type it contains,
has explictly opted out via a _negative impl_.
[`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
```rust
impl !Type for Trait
```
Example:
```rust
#![feature(optin_builtin_traits)]
trait Valid {}
impl Valid for .. {}
struct True;
struct False;
impl !Valid for False {}
struct MaybeValid<T>(T);
fn must_be_valid<T: Valid>(_t: T) {
}
fn main() {
//works
must_be_valid( MaybeValid(True) );
// compiler error - trait bound not satisfied
// must_be_valid( MaybeValid(False) );
}
```