2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
//! Operations on tuples
|
2014-05-26 03:34:51 -05:00
|
|
|
//!
|
|
|
|
//! To access a single element of a tuple one can use the following
|
|
|
|
//! methods:
|
|
|
|
//!
|
|
|
|
//! * `valN` - returns a value of _N_-th element
|
|
|
|
//! * `refN` - returns a reference to _N_-th element
|
|
|
|
//! * `mutN` - returns a mutable reference to _N_-th element
|
|
|
|
//!
|
|
|
|
//! Indexing starts from zero, so `val0` returns first value, `val1`
|
|
|
|
//! returns second value, and so on. In general, a tuple with _S_
|
|
|
|
//! elements provides aforementioned methods suffixed with numbers
|
|
|
|
//! from `0` to `S-1`. Traits which contain these methods are
|
|
|
|
//! implemented for tuples with up to 12 elements.
|
|
|
|
//!
|
|
|
|
//! If every type inside a tuple implements one of the following
|
|
|
|
//! traits, then a tuple itself also implements it.
|
|
|
|
//!
|
|
|
|
//! * `Clone`
|
2014-05-29 19:45:07 -05:00
|
|
|
//! * `PartialEq`
|
2014-05-31 12:43:52 -05:00
|
|
|
//! * `Eq`
|
2014-05-29 19:45:07 -05:00
|
|
|
//! * `PartialOrd`
|
2014-05-31 12:43:52 -05:00
|
|
|
//! * `Ord`
|
2014-05-26 03:34:51 -05:00
|
|
|
//! * `Default`
|
|
|
|
//!
|
|
|
|
//! # Examples
|
|
|
|
//!
|
|
|
|
//! Using methods:
|
|
|
|
//!
|
|
|
|
//! ```
|
2014-04-21 16:58:52 -05:00
|
|
|
//! let pair = ("pi", 3.14f64);
|
2014-05-26 03:34:51 -05:00
|
|
|
//! assert_eq!(pair.val0(), "pi");
|
2014-04-21 16:58:52 -05:00
|
|
|
//! assert_eq!(pair.val1(), 3.14f64);
|
2014-05-26 03:34:51 -05:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! Using traits implemented for tuples:
|
|
|
|
//!
|
|
|
|
//! ```
|
|
|
|
//! use std::default::Default;
|
|
|
|
//!
|
2014-04-21 16:58:52 -05:00
|
|
|
//! let a = (1i, 2i);
|
|
|
|
//! let b = (3i, 4i);
|
2014-05-26 03:34:51 -05:00
|
|
|
//! assert!(a != b);
|
|
|
|
//!
|
|
|
|
//! let c = b.clone();
|
|
|
|
//! assert!(b == c);
|
|
|
|
//!
|
|
|
|
//! let d : (u32, f32) = Default::default();
|
|
|
|
//! assert_eq!(d, (0u32, 0.0f32));
|
|
|
|
//! ```
|
2013-05-28 16:35:52 -05:00
|
|
|
|
2014-05-28 21:53:37 -05:00
|
|
|
#![doc(primitive = "tuple")]
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#![stable]
|
2014-05-28 21:53:37 -05:00
|
|
|
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "this is just a documentation module and should not be part \
|
|
|
|
of the public api"]
|
2014-07-01 19:21:15 -05:00
|
|
|
pub use unit;
|
|
|
|
|
2013-07-02 14:47:32 -05:00
|
|
|
use clone::Clone;
|
2014-06-28 15:57:36 -05:00
|
|
|
use cmp::*;
|
|
|
|
use default::Default;
|
2014-11-28 10:57:41 -06:00
|
|
|
use option::Option;
|
|
|
|
use option::Option::Some;
|
2013-05-18 04:43:14 -05:00
|
|
|
|
2013-05-18 06:38:06 -05:00
|
|
|
// macro for implementing n-ary tuple functions and operations
|
2013-05-19 03:51:14 -05:00
|
|
|
macro_rules! tuple_impls {
|
2013-05-18 06:38:06 -05:00
|
|
|
($(
|
2014-02-16 03:25:28 -06:00
|
|
|
$Tuple:ident {
|
2014-02-16 05:19:41 -06:00
|
|
|
$(($valN:ident, $refN:ident, $mutN:ident) -> $T:ident {
|
|
|
|
($($x:ident),+) => $ret:expr
|
2013-05-18 07:46:02 -05:00
|
|
|
})+
|
2013-03-26 18:08:05 -05:00
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
)+) => {
|
2013-11-29 08:52:38 -06:00
|
|
|
$(
|
2014-10-27 17:37:07 -05:00
|
|
|
#[allow(missing_docs)]
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[stable]
|
2014-02-16 03:25:28 -06:00
|
|
|
pub trait $Tuple<$($T),+> {
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
$(
|
|
|
|
#[unstable = "may rename pending accessor naming conventions"]
|
|
|
|
fn $valN(self) -> $T;
|
|
|
|
#[unstable = "may rename pending accessor naming conventions"]
|
|
|
|
fn $refN<'a>(&'a self) -> &'a $T;
|
|
|
|
#[unstable = "may rename pending accessor naming conventions"]
|
|
|
|
fn $mutN<'a>(&'a mut self) -> &'a mut $T;
|
|
|
|
)+
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2013-05-18 07:46:02 -05:00
|
|
|
|
2014-02-16 03:25:28 -06:00
|
|
|
impl<$($T),+> $Tuple<$($T),+> for ($($T,)+) {
|
2013-11-29 08:52:38 -06:00
|
|
|
$(
|
|
|
|
#[inline]
|
2014-10-27 17:37:07 -05:00
|
|
|
#[allow(unused_variables)]
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "may rename pending accessor naming conventions"]
|
2014-02-16 05:19:41 -06:00
|
|
|
fn $valN(self) -> $T {
|
|
|
|
let ($($x,)+) = self; $ret
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2012-08-27 18:26:35 -05:00
|
|
|
|
2013-11-29 08:52:38 -06:00
|
|
|
#[inline]
|
2014-10-27 17:37:07 -05:00
|
|
|
#[allow(unused_variables)]
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "may rename pending accessor naming conventions"]
|
2014-02-16 05:19:41 -06:00
|
|
|
fn $refN<'a>(&'a self) -> &'a $T {
|
|
|
|
let ($(ref $x,)+) = *self; $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2014-10-27 17:37:07 -05:00
|
|
|
#[allow(unused_variables)]
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "may rename pending accessor naming conventions"]
|
2014-02-16 05:19:41 -06:00
|
|
|
fn $mutN<'a>(&'a mut self) -> &'a mut $T {
|
|
|
|
let ($(ref mut $x,)+) = *self; $ret
|
2012-11-14 20:59:30 -06:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "waiting for Clone to stabilize"]
|
2013-11-29 08:52:38 -06:00
|
|
|
impl<$($T:Clone),+> Clone for ($($T,)+) {
|
|
|
|
fn clone(&self) -> ($($T,)+) {
|
2014-02-16 05:19:41 -06:00
|
|
|
($(self.$refN().clone(),)+)
|
2012-11-14 20:59:30 -06:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2012-08-27 18:26:35 -05:00
|
|
|
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "waiting for PartialEq to stabilize"]
|
2014-05-29 19:45:07 -05:00
|
|
|
impl<$($T:PartialEq),+> PartialEq for ($($T,)+) {
|
2013-11-29 08:52:38 -06:00
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 05:19:41 -06:00
|
|
|
$(*self.$refN() == *other.$refN())&&+
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 05:19:41 -06:00
|
|
|
$(*self.$refN() != *other.$refN())||+
|
2012-11-14 20:59:30 -06:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2012-08-27 18:26:35 -05:00
|
|
|
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "waiting for Eq to stabilize"]
|
2014-05-31 12:43:52 -05:00
|
|
|
impl<$($T:Eq),+> Eq for ($($T,)+) {}
|
2013-05-19 03:51:14 -05:00
|
|
|
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "waiting for PartialOrd to stabilize"]
|
2014-05-29 19:45:07 -05:00
|
|
|
impl<$($T:PartialOrd + PartialEq),+> PartialOrd for ($($T,)+) {
|
2014-06-18 01:25:51 -05:00
|
|
|
#[inline]
|
|
|
|
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
|
|
|
|
lexical_partial_cmp!($(self.$refN(), other.$refN()),+)
|
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
#[inline]
|
|
|
|
fn lt(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 05:19:41 -06:00
|
|
|
lexical_ord!(lt, $(self.$refN(), other.$refN()),+)
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn le(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 05:19:41 -06:00
|
|
|
lexical_ord!(le, $(self.$refN(), other.$refN()),+)
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ge(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 05:19:41 -06:00
|
|
|
lexical_ord!(ge, $(self.$refN(), other.$refN()),+)
|
2013-05-18 06:38:06 -05:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
#[inline]
|
|
|
|
fn gt(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 05:19:41 -06:00
|
|
|
lexical_ord!(gt, $(self.$refN(), other.$refN()),+)
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[unstable = "waiting for Ord to stabilize"]
|
2014-05-31 12:43:52 -05:00
|
|
|
impl<$($T:Ord),+> Ord for ($($T,)+) {
|
2013-11-29 08:52:38 -06:00
|
|
|
#[inline]
|
|
|
|
fn cmp(&self, other: &($($T,)+)) -> Ordering {
|
2014-02-16 05:19:41 -06:00
|
|
|
lexical_cmp!($(self.$refN(), other.$refN()),+)
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
2013-06-14 20:27:52 -05:00
|
|
|
|
std: Stabilize unit, bool, ty, tuple, arc, any
This commit applies stability attributes to the contents of these modules,
summarized here:
* The `unit` and `bool` modules have become #[unstable] as they are purely meant
for documentation purposes and are candidates for removal.
* The `ty` module has been deprecated, and the inner `Unsafe` type has been
renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field
has been removed as the compiler now always infers `UnsafeCell` to be
invariant. The `new` method i stable, but the `value` field, `get` and
`unwrap` methods are all unstable.
* The `tuple` module has its name as stable, the naming of the `TupleN` traits
as stable while the methods are all #[unstable]. The other impls in the module
have appropriate stability for the corresponding trait.
* The `arc` module has received the exact same treatment as the `rc` module
previously did.
* The `any` module has its name as stable. The `Any` trait is also stable, with
a new private supertrait which now contains the `get_type_id` method. This is
to make the method a private implementation detail rather than a public-facing
detail.
The two extension traits in the module are marked #[unstable] as they will not
be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods
have been renamed to downcast_{mut,ref} and are #[unstable].
The extension trait `BoxAny` has been clarified as to why it is unstable as it
will not be necessary with DST.
This is a breaking change because the `marker1` field was removed from the
`UnsafeCell` type. To deal with this change, you can simply delete the field and
only specify the value of the `data` field in static initializers.
[breaking-change]
2014-07-23 21:10:12 -05:00
|
|
|
#[stable]
|
2013-11-29 08:52:38 -06:00
|
|
|
impl<$($T:Default),+> Default for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn default() -> ($($T,)+) {
|
|
|
|
($({ let x: $T = Default::default(); x},)+)
|
2013-09-11 23:49:25 -05:00
|
|
|
}
|
2013-11-29 08:52:38 -06:00
|
|
|
}
|
|
|
|
)+
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:07:22 -05:00
|
|
|
// Constructs an expression that performs a lexical ordering using method $rel.
|
|
|
|
// The values are interleaved, so the macro invocation for
|
|
|
|
// `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_ord!(lt, a1, b1, a2, b2,
|
2013-05-19 03:51:14 -05:00
|
|
|
// a3, b3)` (and similarly for `lexical_cmp`)
|
2013-08-08 15:07:22 -05:00
|
|
|
macro_rules! lexical_ord {
|
|
|
|
($rel: ident, $a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
|
|
|
if *$a != *$b { lexical_ord!($rel, $a, $b) }
|
|
|
|
else { lexical_ord!($rel, $($rest_a, $rest_b),+) }
|
2013-05-19 03:51:14 -05:00
|
|
|
};
|
2013-08-08 15:07:22 -05:00
|
|
|
($rel: ident, $a:expr, $b:expr) => { (*$a) . $rel ($b) };
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
|
|
|
|
2014-06-18 01:25:51 -05:00
|
|
|
macro_rules! lexical_partial_cmp {
|
|
|
|
($a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
|
|
|
match ($a).partial_cmp($b) {
|
|
|
|
Some(Equal) => lexical_partial_cmp!($($rest_a, $rest_b),+),
|
|
|
|
ordering => ordering
|
|
|
|
}
|
|
|
|
};
|
|
|
|
($a:expr, $b:expr) => { ($a).partial_cmp($b) };
|
|
|
|
}
|
|
|
|
|
2013-05-19 03:51:14 -05:00
|
|
|
macro_rules! lexical_cmp {
|
|
|
|
($a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
|
|
|
match ($a).cmp($b) {
|
|
|
|
Equal => lexical_cmp!($($rest_a, $rest_b),+),
|
|
|
|
ordering => ordering
|
|
|
|
}
|
|
|
|
};
|
|
|
|
($a:expr, $b:expr) => { ($a).cmp($b) };
|
|
|
|
}
|
|
|
|
|
|
|
|
tuple_impls! {
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple1 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a) => a }
|
2013-08-08 15:07:21 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple2 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b) => b }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple3 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c) => c }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple4 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d) => d }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple5 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e) => e }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple6 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f) => f }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple7 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g) => g }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple8 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h) => h }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple9 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i) => i }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple10 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j) => i }
|
|
|
|
(val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j) => j }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple11 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j, k) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j, k) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j, k) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j, k) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j, k) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j, k) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j, k) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j, k) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j, k) => i }
|
|
|
|
(val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j, k) => j }
|
|
|
|
(val10, ref10, mut10) -> K { (a, b, c, d, e, f, g, h, i, j, k) => k }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2014-02-16 03:25:28 -06:00
|
|
|
Tuple12 {
|
2014-02-16 05:19:41 -06:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j, k, l) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j, k, l) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j, k, l) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j, k, l) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j, k, l) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j, k, l) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j, k, l) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j, k, l) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j, k, l) => i }
|
|
|
|
(val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j, k, l) => j }
|
|
|
|
(val10, ref10, mut10) -> K { (a, b, c, d, e, f, g, h, i, j, k, l) => k }
|
|
|
|
(val11, ref11, mut11) -> L { (a, b, c, d, e, f, g, h, i, j, k, l) => l }
|
2013-05-18 04:43:14 -05:00
|
|
|
}
|
2013-05-19 03:51:14 -05:00
|
|
|
}
|
2013-05-18 03:59:16 -05:00
|
|
|
|