From a1755b7c9800c0e5b586e89302f5a55e031f4927 Mon Sep 17 00:00:00 2001 From: pfalabella Date: Sat, 3 Jan 2015 23:49:51 +0100 Subject: [PATCH] rustup 2015-01-02 --- src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 96efdd3..8e44712 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,19 +12,21 @@ //! Operations on ASCII strings and characters -#![feature(macro_rules, globs, default_type_params)] +#![feature(macro_rules, globs, default_type_params, old_orphan_check)] +// added old_orphan_check to work around https://github.com/rust-lang/rust/issues/20477 + #![unstable = "unsure about placement and naming"] #![allow(deprecated)] //use std::kinds::Sized; + use std::fmt; use std::mem; use std::borrow::BorrowFrom; use std::ascii::AsciiExt; - /// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero. -#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Copy)] +#[derive(Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Copy)] pub struct Ascii { chr: u8 } impl Ascii { @@ -144,7 +146,7 @@ impl<'a> fmt::Show for Ascii { /// Trait for converting into an ascii type. #[experimental = "may be replaced by generic conversion traits"] -pub trait AsciiCast for Sized?: AsciiExt { +pub trait AsciiCast : AsciiExt { /// Convert to an ascii type, return Err(()) on non-ASCII input. #[inline] fn to_ascii(&self) -> Result { @@ -193,7 +195,7 @@ impl AsciiCast for char { /// Trait for copyless casting to an ascii vector. #[experimental = "may be replaced by generic conversion traits"] -pub trait OwnedAsciiCast +pub trait OwnedAsciiCast : Sized where T: BorrowFrom + AsciiExt { /// Take ownership and cast to an ascii vector. Return Err(()) on non-ASCII input. #[inline] @@ -236,10 +238,17 @@ impl OwnedAsciiCast<[u8]> for Vec { } } +/// Trait for converting a type to a string, consuming it in the process. +#[experimental = "may be replaced by generic conversion traits"] +pub trait IntoString { + /// Consume and convert to a string. + fn into_string(self) -> String; +} + /// Trait for converting an ascii type to a string. Needed to convert /// `&[Ascii]` to `&str`. #[experimental = "may be replaced by generic conversion traits"] -pub trait AsciiStr for Sized? { +pub trait AsciiStr { /// Convert to a string. fn as_str<'a>(&'a self) -> &'a str;