Merge remote-tracking branch 'rust-lang/master'
Conflicts: mk/tests.mk src/liballoc/arc.rs src/liballoc/boxed.rs src/liballoc/rc.rs src/libcollections/bit.rs src/libcollections/btree/map.rs src/libcollections/btree/set.rs src/libcollections/dlist.rs src/libcollections/ring_buf.rs src/libcollections/slice.rs src/libcollections/str.rs src/libcollections/string.rs src/libcollections/vec.rs src/libcollections/vec_map.rs src/libcore/any.rs src/libcore/array.rs src/libcore/borrow.rs src/libcore/error.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/ops.rs src/libcore/result.rs src/libcore/slice.rs src/libcore/str/mod.rs src/libregex/lib.rs src/libregex/re.rs src/librustc/lint/builtin.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mutex.rs src/libstd/sync/poison.rs src/libstd/sync/rwlock.rs src/libsyntax/feature_gate.rs src/libsyntax/test.rs
This commit is contained in:
commit
63fcbcf3ce
433 changed files with 7348 additions and 12011 deletions
|
|
@ -34,11 +34,11 @@
|
|||
//! use runtime reflection instead.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use std::fmt::Show;
|
||||
//! use std::fmt::Debug;
|
||||
//! use std::any::Any;
|
||||
//!
|
||||
//! // Logger function for any type that implements Show.
|
||||
//! fn log<T: Any+Show>(value: &T) {
|
||||
//! // Logger function for any type that implements Debug.
|
||||
//! fn log<T: Any + Debug>(value: &T) {
|
||||
//! let value_any = value as &Any;
|
||||
//!
|
||||
//! // try to convert our value to a String. If successful, we want to
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
//! }
|
||||
//!
|
||||
//! // This function wants to log its parameter out prior to doing work with it.
|
||||
//! fn do_work<T: Show+'static>(value: &T) {
|
||||
//! fn do_work<T: Debug + 'static>(value: &T) {
|
||||
//! log(value);
|
||||
//! // ...do some other work
|
||||
//! }
|
||||
|
|
@ -75,7 +75,7 @@ use mem::transmute;
|
|||
use option::Option::{self, Some, None};
|
||||
use raw::TraitObject;
|
||||
use intrinsics;
|
||||
#[cfg(not(stage0))] use marker::Sized;
|
||||
use marker::Sized;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Any trait
|
||||
|
|
@ -176,7 +176,6 @@ pub struct TypeId {
|
|||
impl TypeId {
|
||||
/// Returns the `TypeId` of the type this generic function has been
|
||||
/// instantiated with
|
||||
#[cfg(not(stage0))]
|
||||
#[unstable(feature = "core",
|
||||
reason = "may grow a `Reflect` bound soon via marker traits")]
|
||||
pub fn of<T: ?Sized + 'static>() -> TypeId {
|
||||
|
|
@ -184,10 +183,4 @@ impl TypeId {
|
|||
t: unsafe { intrinsics::type_id::<T>() },
|
||||
}
|
||||
}
|
||||
|
||||
/// dox
|
||||
#[cfg(stage0)]
|
||||
pub fn of<T: 'static>() -> TypeId {
|
||||
unsafe { intrinsics::type_id::<T>() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,11 +39,10 @@ macro_rules! array_impls {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "core",
|
||||
reason = "waiting for Show to stabilize")]
|
||||
impl<T:fmt::Show> fmt::Show for [T; $N] {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: fmt::Debug> fmt::Debug for [T; $N] {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Show::fmt(&&self[], f)
|
||||
fmt::Debug::fmt(&&self[], f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ impl<T> ToOwned<T> for T where T: Clone {
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Show)]
|
||||
pub enum Cow<'a, T, B: ?Sized + 'a> where B: ToOwned<T> {
|
||||
/// Borrowed data.
|
||||
Borrowed(&'a B),
|
||||
|
|
@ -240,14 +239,27 @@ impl<'a, T, B: ?Sized> PartialOrd for Cow<'a, T, B> where B: PartialOrd + ToOwne
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T, B: ?Sized> fmt::String for Cow<'a, T, B> where
|
||||
B: fmt::String + ToOwned<T>,
|
||||
T: fmt::String,
|
||||
impl<'a, T, B: ?Sized> fmt::Debug for Cow<'a, T, B> where
|
||||
B: fmt::Debug + ToOwned<T>,
|
||||
T: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Borrowed(ref b) => fmt::String::fmt(b, f),
|
||||
Owned(ref o) => fmt::String::fmt(o, f),
|
||||
Borrowed(ref b) => fmt::Debug::fmt(b, f),
|
||||
Owned(ref o) => fmt::Debug::fmt(o, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T, B: ?Sized> fmt::Display for Cow<'a, T, B> where
|
||||
B: fmt::Display + ToOwned<T>,
|
||||
T: fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Borrowed(ref b) => fmt::Display::fmt(b, f),
|
||||
Owned(ref o) => fmt::Display::fmt(o, f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@
|
|||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Note that this example uses `Rc<T>` and not `Arc<T>`. `RefCell<T>`s are for single-threaded
|
||||
//! scenarios. Consider using `Mutex<T>` if you need shared mutability in a multi-threaded
|
||||
//! situation.
|
||||
//!
|
||||
//! ## Implementation details of logically-immutable methods
|
||||
//!
|
||||
//! Occasionally it may be desirable not to expose in an API that
|
||||
|
|
|
|||
112
src/libcore/error.rs
Normal file
112
src/libcore/error.rs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
//! Traits for working with Errors.
|
||||
//!
|
||||
//! # The `Error` trait
|
||||
//!
|
||||
//! `Error` is a trait representing the basic expectations for error values,
|
||||
//! i.e. values of type `E` in `Result<T, E>`. At a minimum, errors must provide
|
||||
//! a description, but they may optionally provide additional detail (via
|
||||
//! `Display`) and cause chain information:
|
||||
//!
|
||||
//! ```
|
||||
//! use std::fmt::Display;
|
||||
//!
|
||||
//! trait Error: Display {
|
||||
//! fn description(&self) -> &str;
|
||||
//!
|
||||
//! fn cause(&self) -> Option<&Error> { None }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! The `cause` method is generally used when errors cross "abstraction
|
||||
//! boundaries", i.e. when a one module must report an error that is "caused"
|
||||
//! by an error from a lower-level module. This setup makes it possible for the
|
||||
//! high-level module to provide its own errors that do not commit to any
|
||||
//! particular implementation, but also reveal some of its implementation for
|
||||
//! debugging via `cause` chains.
|
||||
//!
|
||||
//! # The `FromError` trait
|
||||
//!
|
||||
//! `FromError` is a simple trait that expresses conversions between different
|
||||
//! error types. To provide maximum flexibility, it does not require either of
|
||||
//! the types to actually implement the `Error` trait, although this will be the
|
||||
//! common case.
|
||||
//!
|
||||
//! The main use of this trait is in the `try!` macro, which uses it to
|
||||
//! automatically convert a given error to the error specified in a function's
|
||||
//! return type.
|
||||
//!
|
||||
//! For example,
|
||||
//!
|
||||
//! ```
|
||||
//! use std::error::FromError;
|
||||
//! use std::io::{File, IoError};
|
||||
//! use std::os::{MemoryMap, MapError};
|
||||
//! use std::path::Path;
|
||||
//!
|
||||
//! enum MyError {
|
||||
//! Io(IoError),
|
||||
//! Map(MapError)
|
||||
//! }
|
||||
//!
|
||||
//! impl FromError<IoError> for MyError {
|
||||
//! fn from_error(err: IoError) -> MyError {
|
||||
//! MyError::Io(err)
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! impl FromError<MapError> for MyError {
|
||||
//! fn from_error(err: MapError) -> MyError {
|
||||
//! MyError::Map(err)
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! #[allow(unused_variables)]
|
||||
//! fn open_and_map() -> Result<(), MyError> {
|
||||
//! let f = try!(File::open(&Path::new("foo.txt")));
|
||||
//! let m = try!(MemoryMap::new(0, &[]));
|
||||
//! // do something interesting here...
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use prelude::*;
|
||||
use fmt::Display;
|
||||
|
||||
/// Base functionality for all errors in Rust.
|
||||
#[unstable(feature = "core",
|
||||
reason = "the exact API of this trait may change")]
|
||||
pub trait Error: Display {
|
||||
/// A short description of the error; usually a static string.
|
||||
fn description(&self) -> &str;
|
||||
|
||||
/// The lower-level cause of this error, if any.
|
||||
fn cause(&self) -> Option<&Error> { None }
|
||||
}
|
||||
|
||||
/// A trait for types that can be converted from a given error type `E`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub trait FromError<E> {
|
||||
/// Perform the conversion.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn from_error(err: E) -> Self;
|
||||
}
|
||||
|
||||
// Any type is convertable from itself
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<E> FromError<E> for E {
|
||||
fn from_error(err: E) -> E {
|
||||
err
|
||||
}
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
|
|||
_ => ()
|
||||
}
|
||||
|
||||
buf.slice_to_mut(end).reverse();
|
||||
buf[..end].reverse();
|
||||
|
||||
// Remember start of the fractional digits.
|
||||
// Points one beyond end of buf if none get generated,
|
||||
|
|
@ -316,7 +316,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
|
|||
|
||||
impl<'a> fmt::Writer for Filler<'a> {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
slice::bytes::copy_memory(self.buf.slice_from_mut(*self.end),
|
||||
slice::bytes::copy_memory(&mut self.buf[(*self.end)..],
|
||||
s.as_bytes());
|
||||
*self.end += s.len();
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -26,12 +26,15 @@ use ops::{Deref, FnOnce};
|
|||
use result;
|
||||
use slice::SliceExt;
|
||||
use slice;
|
||||
use str::{self, StrExt, Utf8Error};
|
||||
use str::{self, StrExt};
|
||||
|
||||
pub use self::num::radix;
|
||||
pub use self::num::Radix;
|
||||
pub use self::num::RadixFmt;
|
||||
|
||||
#[cfg(stage0)] pub use self::Debug as Show;
|
||||
#[cfg(stage0)] pub use self::Display as String;
|
||||
|
||||
mod num;
|
||||
mod float;
|
||||
pub mod rt;
|
||||
|
|
@ -48,7 +51,7 @@ pub type Result = result::Result<(), Error>;
|
|||
/// some other means.
|
||||
#[unstable(feature = "core",
|
||||
reason = "core and I/O reconciliation may alter this definition")]
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Show)]
|
||||
pub struct Error;
|
||||
|
||||
/// A collection of methods that are required to format a message into a stream.
|
||||
|
|
@ -138,7 +141,7 @@ pub struct Argument<'a> {
|
|||
impl<'a> Argument<'a> {
|
||||
#[inline(never)]
|
||||
fn show_uint(x: &uint, f: &mut Formatter) -> Result {
|
||||
Show::fmt(x, f)
|
||||
Display::fmt(x, f)
|
||||
}
|
||||
|
||||
fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter) -> Result) -> Argument<'b> {
|
||||
|
|
@ -221,14 +224,15 @@ pub struct Arguments<'a> {
|
|||
args: &'a [Argument<'a>],
|
||||
}
|
||||
|
||||
impl<'a> Show for Arguments<'a> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> Debug for Arguments<'a> {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
String::fmt(self, fmt)
|
||||
Display::fmt(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> String for Arguments<'a> {
|
||||
impl<'a> Display for Arguments<'a> {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
write(fmt.buf, *self)
|
||||
}
|
||||
|
|
@ -238,20 +242,52 @@ impl<'a> String for Arguments<'a> {
|
|||
/// should implement this.
|
||||
#[unstable(feature = "core",
|
||||
reason = "I/O and core have yet to be reconciled")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to Debug")]
|
||||
#[cfg(not(stage0))]
|
||||
pub trait Show {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
/// Format trait for the `:?` format. Useful for debugging, most all types
|
||||
/// should implement this.
|
||||
#[unstable(feature = "core",
|
||||
reason = "I/O and core have yet to be reconciled")]
|
||||
pub trait Debug {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: Show + ?Sized> Debug for T {
|
||||
#[allow(deprecated)]
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Show::fmt(self, f) }
|
||||
}
|
||||
|
||||
/// When a value can be semantically expressed as a String, this trait may be
|
||||
/// used. It corresponds to the default format, `{}`.
|
||||
#[unstable(feature = "core")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to Display")]
|
||||
#[cfg(not(stage0))]
|
||||
pub trait String {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
/// When a value can be semantically expressed as a String, this trait may be
|
||||
/// used. It corresponds to the default format, `{}`.
|
||||
#[unstable(feature = "core",
|
||||
reason = "I/O and core have yet to be reconciled")]
|
||||
pub trait String {
|
||||
pub trait Display {
|
||||
/// Formats the value using the given formatter.
|
||||
fn fmt(&self, &mut Formatter) -> Result;
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: String + ?Sized> Display for T {
|
||||
#[allow(deprecated)]
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { String::fmt(self, f) }
|
||||
}
|
||||
|
||||
/// Format trait for the `o` character
|
||||
#[unstable(feature = "core",
|
||||
|
|
@ -605,9 +641,10 @@ impl<'a> Formatter<'a> {
|
|||
pub fn precision(&self) -> Option<uint> { self.precision }
|
||||
}
|
||||
|
||||
impl Show for Error {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
String::fmt("an error occurred when formatting an argument", f)
|
||||
Display::fmt("an error occurred when formatting an argument", f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -635,9 +672,11 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
|
|||
macro_rules! fmt_refs {
|
||||
($($tr:ident),*) => {
|
||||
$(
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T: ?Sized + $tr> $tr for &'a T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T: ?Sized + $tr> $tr for &'a mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { $tr::fmt(&**self, f) }
|
||||
}
|
||||
|
|
@ -645,22 +684,24 @@ macro_rules! fmt_refs {
|
|||
}
|
||||
}
|
||||
|
||||
fmt_refs! { Show, String, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
|
||||
fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
|
||||
|
||||
impl Show for bool {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Debug for bool {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
String::fmt(self, f)
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl String for bool {
|
||||
impl Display for bool {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
String::fmt(if *self { "true" } else { "false" }, f)
|
||||
Display::fmt(if *self { "true" } else { "false" }, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for str {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Debug for str {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
try!(write!(f, "\""));
|
||||
for c in self.chars().flat_map(|c| c.escape_default()) {
|
||||
|
|
@ -671,13 +712,14 @@ impl Show for str {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl String for str {
|
||||
impl Display for str {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.pad(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for char {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Debug for char {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
use char::CharExt;
|
||||
try!(write!(f, "'"));
|
||||
|
|
@ -689,15 +731,16 @@ impl Show for char {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl String for char {
|
||||
impl Display for char {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
let mut utf8 = [0u8; 4];
|
||||
let amt = self.encode_utf8(&mut utf8).unwrap_or(0);
|
||||
let s: &str = unsafe { mem::transmute(&utf8[..amt]) };
|
||||
String::fmt(s, f)
|
||||
Display::fmt(s, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Pointer for *const T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.flags |= 1 << (rt::FlagAlternate as uint);
|
||||
|
|
@ -707,18 +750,21 @@ impl<T> Pointer for *const T {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Pointer for *mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Pointer::fmt(&(*self as *const T), f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T> Pointer for &'a T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Pointer::fmt(&(*self as *const T), f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T> Pointer for &'a mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Pointer::fmt(&(&**self as *const T), f)
|
||||
|
|
@ -727,15 +773,15 @@ impl<'a, T> Pointer for &'a mut T {
|
|||
|
||||
macro_rules! floating { ($ty:ident) => {
|
||||
|
||||
impl Show for $ty {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Debug for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
try!(String::fmt(self, fmt));
|
||||
fmt.write_str(stringify!($ty))
|
||||
Display::fmt(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl String for $ty {
|
||||
impl Display for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
use num::Float;
|
||||
|
||||
|
|
@ -756,6 +802,7 @@ macro_rules! floating { ($ty:ident) => {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl LowerExp for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
use num::Float;
|
||||
|
|
@ -777,6 +824,7 @@ macro_rules! floating { ($ty:ident) => {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl UpperExp for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
use num::Float;
|
||||
|
|
@ -801,12 +849,14 @@ macro_rules! floating { ($ty:ident) => {
|
|||
floating! { f32 }
|
||||
floating! { f64 }
|
||||
|
||||
// Implementation of Show for various core types
|
||||
// Implementation of Display/Debug for various core types
|
||||
|
||||
impl<T> Show for *const T {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Debug for *const T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
impl<T> Show for *mut T {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Debug for *mut T {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { Pointer::fmt(self, f) }
|
||||
}
|
||||
|
||||
|
|
@ -817,7 +867,8 @@ macro_rules! peel {
|
|||
macro_rules! tuple {
|
||||
() => ();
|
||||
( $($name:ident,)+ ) => (
|
||||
impl<$($name:Show),*> Show for ($($name,)*) {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<$($name:Debug),*> Debug for ($($name,)*) {
|
||||
#[allow(non_snake_case, unused_assignments)]
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
try!(write!(f, "("));
|
||||
|
|
@ -842,11 +893,13 @@ macro_rules! tuple {
|
|||
|
||||
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
|
||||
|
||||
impl<'a> Show for &'a (any::Any+'a) {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> Debug for &'a (any::Any+'a) {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
|
||||
}
|
||||
|
||||
impl<T: Show> Show for [T] {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Debug> Debug for [T] {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
|
||||
try!(write!(f, "["));
|
||||
|
|
@ -867,20 +920,22 @@ impl<T: Show> Show for [T] {
|
|||
}
|
||||
}
|
||||
|
||||
impl Show for () {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Debug for () {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.pad("()")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + Show> Show for Cell<T> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Copy + Debug> Debug for Cell<T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
write!(f, "Cell {{ value: {:?} }}", self.get())
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "core")]
|
||||
impl<T: Show> Show for RefCell<T> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Debug> Debug for RefCell<T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self.try_borrow() {
|
||||
Some(val) => write!(f, "RefCell {{ value: {:?} }}", val),
|
||||
|
|
@ -889,29 +944,17 @@ impl<T: Show> Show for RefCell<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Show> Show for Ref<'b, T> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'b, T: Debug> Debug for Ref<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Show::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T: Show> Show for RefMut<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
Show::fmt(&*(self.deref()), f)
|
||||
Debug::fmt(&**self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl String for Utf8Error {
|
||||
impl<'b, T: Debug> Debug for RefMut<'b, T> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match *self {
|
||||
Utf8Error::InvalidByte(n) => {
|
||||
write!(f, "invalid utf-8: invalid byte at index {}", n)
|
||||
}
|
||||
Utf8Error::TooShort => {
|
||||
write!(f, "invalid utf-8: byte slice too short")
|
||||
}
|
||||
}
|
||||
Debug::fmt(&*(self.deref()), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,13 +157,14 @@ pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
|
|||
|
||||
macro_rules! radix_fmt {
|
||||
($T:ty as $U:ty, $fmt:ident, $S:expr) => {
|
||||
impl fmt::Show for RadixFmt<$T, Radix> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Debug for RadixFmt<$T, Radix> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(fmt::String::fmt(self, f));
|
||||
f.write_str($S)
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
impl fmt::String for RadixFmt<$T, Radix> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Display for RadixFmt<$T, Radix> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self { RadixFmt(ref x, radix) => radix.$fmt(*x as $U, f) }
|
||||
}
|
||||
|
|
@ -172,6 +173,7 @@ macro_rules! radix_fmt {
|
|||
}
|
||||
macro_rules! int_base {
|
||||
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::$Trait for $T {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
$Radix.fmt_int(*self as $U, f)
|
||||
|
|
@ -182,10 +184,10 @@ macro_rules! int_base {
|
|||
|
||||
macro_rules! show {
|
||||
($T:ident with $S:expr) => {
|
||||
impl fmt::Show for $T {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Debug for $T {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(fmt::String::fmt(self, f));
|
||||
f.write_str($S)
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -195,7 +197,7 @@ macro_rules! integer {
|
|||
integer! { $Int, $Uint, stringify!($Int), stringify!($Uint) }
|
||||
};
|
||||
($Int:ident, $Uint:ident, $SI:expr, $SU:expr) => {
|
||||
int_base! { String for $Int as $Int -> Decimal }
|
||||
int_base! { Display for $Int as $Int -> Decimal }
|
||||
int_base! { Binary for $Int as $Uint -> Binary }
|
||||
int_base! { Octal for $Int as $Uint -> Octal }
|
||||
int_base! { LowerHex for $Int as $Uint -> LowerHex }
|
||||
|
|
@ -203,7 +205,7 @@ macro_rules! integer {
|
|||
radix_fmt! { $Int as $Int, fmt_int, $SI }
|
||||
show! { $Int with $SI }
|
||||
|
||||
int_base! { String for $Uint as $Uint -> Decimal }
|
||||
int_base! { Display for $Uint as $Uint -> Decimal }
|
||||
int_base! { Binary for $Uint as $Uint -> Binary }
|
||||
int_base! { Octal for $Uint as $Uint -> Octal }
|
||||
int_base! { LowerHex for $Uint as $Uint -> LowerHex }
|
||||
|
|
|
|||
|
|
@ -44,8 +44,6 @@
|
|||
|
||||
use marker::Sized;
|
||||
|
||||
#[cfg(stage0)] use any::TypeId;
|
||||
|
||||
pub type GlueFn = extern "Rust" fn(*const i8);
|
||||
|
||||
#[lang="ty_desc"]
|
||||
|
|
@ -208,12 +206,8 @@ extern "rust-intrinsic" {
|
|||
/// Gets an identifier which is globally unique to the specified type. This
|
||||
/// function will return the same value for a type regardless of whichever
|
||||
/// crate it is invoked in.
|
||||
#[cfg(not(stage0))]
|
||||
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn type_id<T: ?Sized + 'static>() -> TypeId;
|
||||
|
||||
/// Create a value initialized to zero.
|
||||
///
|
||||
/// `init` is unsafe because it returns a zeroed-out datum,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -64,6 +64,8 @@
|
|||
#![feature(unboxed_closures)]
|
||||
#![allow(unknown_features)] #![feature(int_uint)]
|
||||
#![feature(on_unimplemented)]
|
||||
// FIXME(#21363) remove `old_impl_check` when bug is fixed
|
||||
#![feature(old_impl_check)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
@ -137,6 +139,7 @@ pub mod slice;
|
|||
pub mod str;
|
||||
pub mod hash;
|
||||
pub mod fmt;
|
||||
pub mod error;
|
||||
|
||||
// note: does not need to be public
|
||||
mod tuple;
|
||||
|
|
|
|||
|
|
@ -386,17 +386,6 @@ pub struct ContravariantLifetime<'a>;
|
|||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct InvariantLifetime<'a>;
|
||||
|
||||
/// A type which is considered "not sendable", meaning that it cannot
|
||||
/// be safely sent between tasks, even if it is owned. This is
|
||||
/// typically embedded in other types, such as `Gc`, to ensure that
|
||||
/// their instances remain thread-local.
|
||||
#[unstable(feature = "core",
|
||||
reason = "likely to change with new variance strategy")]
|
||||
#[lang="no_send_bound"]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg(stage0)] // NOTE remove impl after next snapshot
|
||||
pub struct NoSend;
|
||||
|
||||
/// A type which is considered "not POD", meaning that it is not
|
||||
/// implicitly copyable. This is typically embedded in other types to
|
||||
/// ensure that they are never copied, even if they lack a destructor.
|
||||
|
|
@ -407,16 +396,6 @@ pub struct NoSend;
|
|||
#[allow(missing_copy_implementations)]
|
||||
pub struct NoCopy;
|
||||
|
||||
/// A type which is considered "not sync", meaning that
|
||||
/// its contents are not threadsafe, hence they cannot be
|
||||
/// shared between tasks.
|
||||
#[unstable(feature = "core",
|
||||
reason = "likely to change with new variance strategy")]
|
||||
#[lang="no_sync_bound"]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg(stage0)] // NOTE remove impl after next snapshot
|
||||
pub struct NoSync;
|
||||
|
||||
/// A type which is considered managed by the GC. This is typically
|
||||
/// embedded in other types.
|
||||
#[unstable(feature = "core",
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@
|
|||
//! demonstrates adding and subtracting two `Point`s.
|
||||
//!
|
||||
//! ```rust
|
||||
//! #![feature(associated_types)]
|
||||
//!
|
||||
//! use std::ops::{Add, Sub};
|
||||
//!
|
||||
//! #[derive(Show)]
|
||||
|
|
@ -69,10 +67,7 @@
|
|||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use clone::Clone;
|
||||
use iter::{Step, Iterator,DoubleEndedIterator,ExactSizeIterator};
|
||||
use marker::Sized;
|
||||
use option::Option::{self, Some, None};
|
||||
use fmt;
|
||||
|
||||
/// The `Drop` trait is used to run some code when a value goes out of scope. This
|
||||
|
|
@ -168,8 +163,6 @@ macro_rules! forward_ref_binop {
|
|||
/// calling `add`, and therefore, `main` prints `Adding!`.
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Add;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -223,8 +216,6 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Sub;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -278,8 +269,6 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||
/// calling `mul`, and therefore, `main` prints `Multiplying!`.
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Mul;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -333,8 +322,6 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||
/// calling `div`, and therefore, `main` prints `Dividing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Div;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -388,8 +375,6 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 }
|
|||
/// calling `rem`, and therefore, `main` prints `Remainder-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Rem;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -462,8 +447,6 @@ rem_float_impl! { f64, fmod }
|
|||
/// `neg`, and therefore, `main` prints `Negating!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Neg;
|
||||
///
|
||||
/// struct Foo;
|
||||
|
|
@ -541,8 +524,6 @@ neg_uint_impl! { u64, i64 }
|
|||
/// `not`, and therefore, `main` prints `Not-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Not;
|
||||
///
|
||||
/// struct Foo;
|
||||
|
|
@ -597,8 +578,6 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||
/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::BitAnd;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -652,8 +631,6 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::BitOr;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -707,8 +684,6 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::BitXor;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -762,8 +737,6 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
|
|||
/// calling `shl`, and therefore, `main` prints `Shifting left!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Shl;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -835,8 +808,6 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
|
|||
/// calling `shr`, and therefore, `main` prints `Shifting right!`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Shr;
|
||||
///
|
||||
/// #[derive(Copy)]
|
||||
|
|
@ -928,10 +899,12 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
|
|||
/// }
|
||||
/// ```
|
||||
#[lang="index"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub trait Index<Index: ?Sized> {
|
||||
type Output: ?Sized;
|
||||
|
||||
/// The method for the indexing (`Foo[Bar]`) operation
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn index<'a>(&'a self, index: &Index) -> &'a Self::Output;
|
||||
}
|
||||
|
||||
|
|
@ -964,30 +937,32 @@ pub trait Index<Index: ?Sized> {
|
|||
/// }
|
||||
/// ```
|
||||
#[lang="index_mut"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub trait IndexMut<Index: ?Sized> {
|
||||
type Output: ?Sized;
|
||||
|
||||
/// The method for the indexing (`Foo[Bar]`) operation
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Self::Output;
|
||||
}
|
||||
|
||||
/// An unbounded range.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="full_range"]
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
#[unstable(feature = "core", reason = "may be renamed to RangeFull")]
|
||||
pub struct FullRange;
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl fmt::Show for FullRange {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Debug for FullRange {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Show::fmt("..", fmt)
|
||||
fmt::Debug::fmt("..", fmt)
|
||||
}
|
||||
}
|
||||
|
||||
/// A (half-open) range which is bounded at both ends.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="range"]
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Range<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
pub start: Idx,
|
||||
|
|
@ -995,49 +970,8 @@ pub struct Range<Idx> {
|
|||
pub end: Idx,
|
||||
}
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl<Idx: Clone + Step> Iterator for Range<Idx> {
|
||||
type Item = Idx;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Idx> {
|
||||
if self.start < self.end {
|
||||
let result = self.start.clone();
|
||||
self.start.step();
|
||||
return Some(result);
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||
if let Some(hint) = Step::steps_between(&self.start, &self.end) {
|
||||
(hint, Some(hint))
|
||||
} else {
|
||||
(0, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl<Idx: Clone + Step> DoubleEndedIterator for Range<Idx> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<Idx> {
|
||||
if self.start < self.end {
|
||||
self.end.step_back();
|
||||
return Some(self.end.clone());
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl<Idx: Clone + Step> ExactSizeIterator for Range<Idx> {}
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl<Idx: fmt::Show> fmt::Show for Range<Idx> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{:?}..{:?}", self.start, self.end)
|
||||
}
|
||||
|
|
@ -1046,27 +980,16 @@ impl<Idx: fmt::Show> fmt::Show for Range<Idx> {
|
|||
/// A range which is only bounded below.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="range_from"]
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct RangeFrom<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
pub start: Idx,
|
||||
}
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl<Idx: Clone + Step> Iterator for RangeFrom<Idx> {
|
||||
type Item = Idx;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Idx> {
|
||||
// Deliberately overflow so we loop forever.
|
||||
let result = self.start.clone();
|
||||
self.start.step();
|
||||
return Some(result);
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl<Idx: fmt::Show> fmt::Show for RangeFrom<Idx> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{:?}..", self.start)
|
||||
}
|
||||
|
|
@ -1075,14 +998,14 @@ impl<Idx: fmt::Show> fmt::Show for RangeFrom<Idx> {
|
|||
/// A range which is only bounded above.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[lang="range_to"]
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct RangeTo<Idx> {
|
||||
/// The upper bound of the range (exclusive).
|
||||
pub end: Idx,
|
||||
}
|
||||
|
||||
#[unstable(feature = "core", reason = "API still in development")]
|
||||
impl<Idx: fmt::Show> fmt::Show for RangeTo<Idx> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "..{:?}", self.end)
|
||||
}
|
||||
|
|
@ -1098,8 +1021,6 @@ impl<Idx: fmt::Show> fmt::Show for RangeTo<Idx> {
|
|||
/// struct.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::Deref;
|
||||
///
|
||||
/// struct DerefExample<T> {
|
||||
|
|
@ -1153,8 +1074,6 @@ impl<'a, T: ?Sized> Deref for &'a mut T {
|
|||
/// struct.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(associated_types)]
|
||||
///
|
||||
/// use std::ops::{Deref, DerefMut};
|
||||
///
|
||||
/// struct DerefMutExample<T> {
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@
|
|||
use self::Result::{Ok, Err};
|
||||
|
||||
use clone::Clone;
|
||||
use fmt::Show;
|
||||
use fmt::Display;
|
||||
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
|
||||
use ops::{FnMut, FnOnce};
|
||||
use option::Option::{self, None, Some};
|
||||
|
|
@ -715,7 +715,7 @@ impl<T, E> Result<T, E> {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, E: Show> Result<T, E> {
|
||||
impl<T, E: Display> Result<T, E> {
|
||||
/// Unwraps a result, yielding the content of an `Ok`.
|
||||
///
|
||||
/// # Panics
|
||||
|
|
@ -740,13 +740,13 @@ impl<T, E: Show> Result<T, E> {
|
|||
match self {
|
||||
Ok(t) => t,
|
||||
Err(e) =>
|
||||
panic!("called `Result::unwrap()` on an `Err` value: {:?}", e)
|
||||
panic!("called `Result::unwrap()` on an `Err` value: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Show, E> Result<T, E> {
|
||||
impl<T: Display, E> Result<T, E> {
|
||||
/// Unwraps a result, yielding the content of an `Err`.
|
||||
///
|
||||
/// # Panics
|
||||
|
|
@ -770,7 +770,7 @@ impl<T: Show, E> Result<T, E> {
|
|||
pub fn unwrap_err(self) -> E {
|
||||
match self {
|
||||
Ok(t) =>
|
||||
panic!("called `Result::unwrap_err()` on an `Ok` value: {:?}", t),
|
||||
panic!("called `Result::unwrap_err()` on an `Ok` value: {}", t),
|
||||
Err(e) => e
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,9 +67,6 @@ use raw::Slice as RawSlice;
|
|||
pub trait SliceExt {
|
||||
type Item;
|
||||
|
||||
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [Self::Item];
|
||||
fn slice_from<'a>(&'a self, start: uint) -> &'a [Self::Item];
|
||||
fn slice_to<'a>(&'a self, end: uint) -> &'a [Self::Item];
|
||||
fn split_at<'a>(&'a self, mid: uint) -> (&'a [Self::Item], &'a [Self::Item]);
|
||||
fn iter<'a>(&'a self) -> Iter<'a, Self::Item>;
|
||||
fn split<'a, P>(&'a self, pred: P) -> Split<'a, Self::Item, P>
|
||||
|
|
@ -93,9 +90,6 @@ pub trait SliceExt {
|
|||
fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut Self::Item>;
|
||||
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [Self::Item];
|
||||
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [Self::Item];
|
||||
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [Self::Item];
|
||||
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [Self::Item];
|
||||
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, Self::Item>;
|
||||
fn first_mut<'a>(&'a mut self) -> Option<&'a mut Self::Item>;
|
||||
fn tail_mut<'a>(&'a mut self) -> &'a mut [Self::Item];
|
||||
|
|
@ -135,28 +129,6 @@ pub trait SliceExt {
|
|||
impl<T> SliceExt for [T] {
|
||||
type Item = T;
|
||||
|
||||
#[inline]
|
||||
fn slice(&self, start: uint, end: uint) -> &[T] {
|
||||
assert!(start <= end);
|
||||
assert!(end <= self.len());
|
||||
unsafe {
|
||||
transmute(RawSlice {
|
||||
data: self.as_ptr().offset(start as int),
|
||||
len: (end - start)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from(&self, start: uint) -> &[T] {
|
||||
self.slice(start, self.len())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to(&self, end: uint) -> &[T] {
|
||||
self.slice(0, end)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn split_at(&self, mid: uint) -> (&[T], &[T]) {
|
||||
(&self[..mid], &self[mid..])
|
||||
|
|
@ -240,7 +212,7 @@ impl<T> SliceExt for [T] {
|
|||
|
||||
#[inline]
|
||||
fn init(&self) -> &[T] {
|
||||
&self[..(self.len() - 1)]
|
||||
&self[..self.len() - 1]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -291,20 +263,6 @@ impl<T> SliceExt for [T] {
|
|||
#[inline]
|
||||
fn as_mut_slice(&mut self) -> &mut [T] { self }
|
||||
|
||||
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [T] {
|
||||
ops::IndexMut::index_mut(self, &ops::Range { start: start, end: end } )
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from_mut(&mut self, start: uint) -> &mut [T] {
|
||||
ops::IndexMut::index_mut(self, &ops::RangeFrom { start: start } )
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to_mut(&mut self, end: uint) -> &mut [T] {
|
||||
ops::IndexMut::index_mut(self, &ops::RangeTo { end: end } )
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
|
||||
unsafe {
|
||||
|
|
@ -345,13 +303,13 @@ impl<T> SliceExt for [T] {
|
|||
|
||||
#[inline]
|
||||
fn tail_mut(&mut self) -> &mut [T] {
|
||||
self.slice_from_mut(1)
|
||||
&mut self[1 ..]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn init_mut(&mut self) -> &mut [T] {
|
||||
let len = self.len();
|
||||
self.slice_to_mut(len-1)
|
||||
&mut self[.. (len - 1)]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -449,7 +407,7 @@ impl<T> SliceExt for [T] {
|
|||
#[inline]
|
||||
fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq {
|
||||
let (m, n) = (self.len(), needle.len());
|
||||
m >= n && needle == &self[(m-n)..]
|
||||
m >= n && needle == &self[m-n..]
|
||||
}
|
||||
|
||||
#[unstable(feature = "core")]
|
||||
|
|
@ -483,7 +441,7 @@ impl<T> SliceExt for [T] {
|
|||
self.swap(j, i-1);
|
||||
|
||||
// Step 4: Reverse the (previously) weakly decreasing part
|
||||
self.slice_from_mut(i).reverse();
|
||||
self[i..].reverse();
|
||||
|
||||
true
|
||||
}
|
||||
|
|
@ -505,7 +463,7 @@ impl<T> SliceExt for [T] {
|
|||
}
|
||||
|
||||
// Step 2: Reverse the weakly increasing part
|
||||
self.slice_from_mut(i).reverse();
|
||||
self[i..].reverse();
|
||||
|
||||
// Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
|
||||
let mut j = self.len() - 1;
|
||||
|
|
@ -522,8 +480,8 @@ impl<T> SliceExt for [T] {
|
|||
#[inline]
|
||||
fn clone_from_slice(&mut self, src: &[T]) -> uint where T: Clone {
|
||||
let min = cmp::min(self.len(), src.len());
|
||||
let dst = self.slice_to_mut(min);
|
||||
let src = src.slice_to(min);
|
||||
let dst = &mut self[.. min];
|
||||
let src = &src[.. min];
|
||||
for i in range(0, min) {
|
||||
dst[i].clone_from(&src[i]);
|
||||
}
|
||||
|
|
@ -531,6 +489,7 @@ impl<T> SliceExt for [T] {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::Index<uint> for [T] {
|
||||
type Output = T;
|
||||
|
||||
|
|
@ -541,6 +500,7 @@ impl<T> ops::Index<uint> for [T] {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::IndexMut<uint> for [T] {
|
||||
type Output = T;
|
||||
|
||||
|
|
@ -551,6 +511,7 @@ impl<T> ops::IndexMut<uint> for [T] {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::Index<ops::Range<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -565,6 +526,7 @@ impl<T> ops::Index<ops::Range<uint>> for [T] {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -572,6 +534,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
|
|||
self.index(&ops::Range{ start: 0, end: index.end })
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -579,6 +542,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
|
|||
self.index(&ops::Range{ start: index.start, end: self.len() })
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::Index<ops::FullRange> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -587,6 +551,7 @@ impl<T> ops::Index<ops::FullRange> for [T] {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -601,6 +566,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -608,6 +574,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
|
|||
self.index_mut(&ops::Range{ start: 0, end: index.end })
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -616,6 +583,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
|
|||
self.index_mut(&ops::Range{ start: index.start, end: len })
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ops::IndexMut<ops::FullRange> for [T] {
|
||||
type Output = [T];
|
||||
#[inline]
|
||||
|
|
@ -974,7 +942,7 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool {
|
|||
None => self.finish(),
|
||||
Some(idx) => {
|
||||
let ret = Some(&self.v[..idx]);
|
||||
self.v = &self.v[(idx + 1)..];
|
||||
self.v = &self.v[idx + 1..];
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
|
@ -999,7 +967,7 @@ impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> boo
|
|||
match self.v.iter().rposition(|x| (self.pred)(x)) {
|
||||
None => self.finish(),
|
||||
Some(idx) => {
|
||||
let ret = Some(&self.v[(idx + 1)..]);
|
||||
let ret = Some(&self.v[idx + 1..]);
|
||||
self.v = &self.v[..idx];
|
||||
ret
|
||||
}
|
||||
|
|
@ -1052,7 +1020,7 @@ impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
|
|||
Some(idx) => {
|
||||
let tmp = mem::replace(&mut self.v, &mut []);
|
||||
let (head, tail) = tmp.split_at_mut(idx);
|
||||
self.v = tail.slice_from_mut(1);
|
||||
self.v = &mut tail[1..];
|
||||
Some(head)
|
||||
}
|
||||
}
|
||||
|
|
@ -1088,7 +1056,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
|
|||
let tmp = mem::replace(&mut self.v, &mut []);
|
||||
let (head, tail) = tmp.split_at_mut(idx);
|
||||
self.v = head;
|
||||
Some(tail.slice_from_mut(1))
|
||||
Some(&mut tail[1..])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1270,6 +1238,9 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
|
||||
|
||||
#[unstable(feature = "core", reason = "trait is experimental")]
|
||||
impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
|
||||
#[inline]
|
||||
|
|
@ -1348,6 +1319,8 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
|
||||
|
||||
//
|
||||
// Free functions
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ use self::Searcher::{Naive, TwoWay, TwoWayLong};
|
|||
|
||||
use cmp::{self, Eq};
|
||||
use default::Default;
|
||||
use iter::range;
|
||||
use error::Error;
|
||||
use fmt;
|
||||
use iter::ExactSizeIterator;
|
||||
use iter::range;
|
||||
use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator};
|
||||
use marker::Sized;
|
||||
use mem;
|
||||
|
|
@ -247,6 +249,30 @@ impl<'a> CharEq for &'a [char] {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Error for Utf8Error {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Utf8Error::TooShort => "invalid utf-8: not enough bytes",
|
||||
Utf8Error::InvalidByte(..) => "invalid utf-8: corrupt contents",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Display for Utf8Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Utf8Error::InvalidByte(n) => {
|
||||
write!(f, "invalid utf-8: invalid byte at index {}", n)
|
||||
}
|
||||
Utf8Error::TooShort => {
|
||||
write!(f, "invalid utf-8: byte slice too short")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Section: Iterators
|
||||
*/
|
||||
|
|
@ -907,13 +933,13 @@ impl<'a> Iterator for SplitStr<'a> {
|
|||
|
||||
match self.it.next() {
|
||||
Some((from, to)) => {
|
||||
let ret = Some(self.it.haystack.slice(self.last_end, from));
|
||||
let ret = Some(&self.it.haystack[self.last_end .. from]);
|
||||
self.last_end = to;
|
||||
ret
|
||||
}
|
||||
None => {
|
||||
self.finished = true;
|
||||
Some(self.it.haystack.slice(self.last_end, self.it.haystack.len()))
|
||||
Some(&self.it.haystack[self.last_end .. self.it.haystack.len()])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1121,27 +1147,90 @@ mod traits {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a slice of the given string from the byte range
|
||||
/// [`begin`..`end`).
|
||||
///
|
||||
/// This operation is `O(1)`.
|
||||
///
|
||||
/// Panics when `begin` and `end` do not point to valid characters
|
||||
/// or point beyond the last character of the string.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let s = "Löwe 老虎 Léopard";
|
||||
/// assert_eq!(&s[0 .. 1], "L");
|
||||
///
|
||||
/// assert_eq!(&s[1 .. 9], "öwe 老");
|
||||
///
|
||||
/// // these will panic:
|
||||
/// // byte 2 lies within `ö`:
|
||||
/// // &s[2 ..3];
|
||||
///
|
||||
/// // byte 8 lies within `老`
|
||||
/// // &s[1 .. 8];
|
||||
///
|
||||
/// // byte 100 is outside the string
|
||||
/// // &s[3 .. 100];
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ops::Index<ops::Range<uint>> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn index(&self, index: &ops::Range<uint>) -> &str {
|
||||
self.slice(index.start, index.end)
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if index.start <= index.end &&
|
||||
self.is_char_boundary(index.start) &&
|
||||
self.is_char_boundary(index.end) {
|
||||
unsafe { self.slice_unchecked(index.start, index.end) }
|
||||
} else {
|
||||
super::slice_error_fail(self, index.start, index.end)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a slice of the string from the beginning to byte
|
||||
/// `end`.
|
||||
///
|
||||
/// Equivalent to `self[0 .. end]`.
|
||||
///
|
||||
/// Panics when `end` does not point to a valid character, or is
|
||||
/// out of bounds.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ops::Index<ops::RangeTo<uint>> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn index(&self, index: &ops::RangeTo<uint>) -> &str {
|
||||
self.slice_to(index.end)
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if self.is_char_boundary(index.end) {
|
||||
unsafe { self.slice_unchecked(0, index.end) }
|
||||
} else {
|
||||
super::slice_error_fail(self, 0, index.end)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a slice of the string from `begin` to its end.
|
||||
///
|
||||
/// Equivalent to `self[begin .. self.len()]`.
|
||||
///
|
||||
/// Panics when `begin` does not point to a valid character, or is
|
||||
/// out of bounds.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ops::Index<ops::RangeFrom<uint>> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
|
||||
self.slice_from(index.start)
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if self.is_char_boundary(index.start) {
|
||||
unsafe { self.slice_unchecked(index.start, self.len()) }
|
||||
} else {
|
||||
super::slice_error_fail(self, index.start, self.len())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ops::Index<ops::FullRange> for str {
|
||||
type Output = str;
|
||||
#[inline]
|
||||
|
|
@ -1154,7 +1243,7 @@ mod traits {
|
|||
/// Any string that can be represented as a slice
|
||||
#[unstable(feature = "core",
|
||||
reason = "Instead of taking this bound generically, this trait will be \
|
||||
replaced with one of slicing syntax, deref coercions, or \
|
||||
replaced with one of slicing syntax (&foo[]), deref coercions, or \
|
||||
a more generic conversion trait")]
|
||||
pub trait Str {
|
||||
/// Work with `self` as a slice.
|
||||
|
|
@ -1216,9 +1305,6 @@ pub trait StrExt {
|
|||
fn lines<'a>(&'a self) -> Lines<'a>;
|
||||
fn lines_any<'a>(&'a self) -> LinesAny<'a>;
|
||||
fn char_len(&self) -> uint;
|
||||
fn slice<'a>(&'a self, begin: uint, end: uint) -> &'a str;
|
||||
fn slice_from<'a>(&'a self, begin: uint) -> &'a str;
|
||||
fn slice_to<'a>(&'a self, end: uint) -> &'a str;
|
||||
fn slice_chars<'a>(&'a self, begin: uint, end: uint) -> &'a str;
|
||||
unsafe fn slice_unchecked<'a>(&'a self, begin: uint, end: uint) -> &'a str;
|
||||
fn starts_with(&self, pat: &str) -> bool;
|
||||
|
|
@ -1340,7 +1426,7 @@ impl StrExt for str {
|
|||
fn lines_any(&self) -> LinesAny {
|
||||
fn f(line: &str) -> &str {
|
||||
let l = line.len();
|
||||
if l > 0 && line.as_bytes()[l - 1] == b'\r' { line.slice(0, l - 1) }
|
||||
if l > 0 && line.as_bytes()[l - 1] == b'\r' { &line[0 .. l - 1] }
|
||||
else { line }
|
||||
}
|
||||
|
||||
|
|
@ -1351,38 +1437,6 @@ impl StrExt for str {
|
|||
#[inline]
|
||||
fn char_len(&self) -> uint { self.chars().count() }
|
||||
|
||||
#[inline]
|
||||
fn slice(&self, begin: uint, end: uint) -> &str {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if begin <= end &&
|
||||
self.is_char_boundary(begin) &&
|
||||
self.is_char_boundary(end) {
|
||||
unsafe { self.slice_unchecked(begin, end) }
|
||||
} else {
|
||||
slice_error_fail(self, begin, end)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_from(&self, begin: uint) -> &str {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if self.is_char_boundary(begin) {
|
||||
unsafe { self.slice_unchecked(begin, self.len()) }
|
||||
} else {
|
||||
slice_error_fail(self, begin, self.len())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn slice_to(&self, end: uint) -> &str {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
if self.is_char_boundary(end) {
|
||||
unsafe { self.slice_unchecked(0, end) }
|
||||
} else {
|
||||
slice_error_fail(self, 0, end)
|
||||
}
|
||||
}
|
||||
|
||||
fn slice_chars(&self, begin: uint, end: uint) -> &str {
|
||||
assert!(begin <= end);
|
||||
let mut count = 0;
|
||||
|
|
@ -1423,7 +1477,7 @@ impl StrExt for str {
|
|||
#[inline]
|
||||
fn ends_with(&self, needle: &str) -> bool {
|
||||
let (m, n) = (self.len(), needle.len());
|
||||
m >= n && needle.as_bytes() == &self.as_bytes()[(m-n)..]
|
||||
m >= n && needle.as_bytes() == &self.as_bytes()[m-n..]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue