|
12 | 12 |
|
13 | 13 | //! Operations on ASCII strings and characters
|
14 | 14 |
|
15 |
| -#![feature(macro_rules, globs, default_type_params)] |
| 15 | +#![feature(macro_rules, globs, default_type_params, old_orphan_check)] |
| 16 | +// added old_orphan_check to work around https://github.com/rust-lang/rust/issues/20477 |
| 17 | + |
16 | 18 | #![unstable = "unsure about placement and naming"]
|
17 | 19 | #![allow(deprecated)]
|
18 | 20 |
|
19 | 21 | //use std::kinds::Sized;
|
| 22 | + |
20 | 23 | use std::fmt;
|
21 | 24 | use std::mem;
|
22 | 25 | use std::borrow::BorrowFrom;
|
23 | 26 | use std::ascii::AsciiExt;
|
24 | 27 |
|
25 |
| - |
26 | 28 | /// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
|
27 |
| -#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Copy)] |
| 29 | +#[derive(Clone, PartialEq, PartialOrd, Ord, Eq, Hash, Copy)] |
28 | 30 | pub struct Ascii { chr: u8 }
|
29 | 31 |
|
30 | 32 | impl Ascii {
|
@@ -144,7 +146,7 @@ impl<'a> fmt::Show for Ascii {
|
144 | 146 |
|
145 | 147 | /// Trait for converting into an ascii type.
|
146 | 148 | #[experimental = "may be replaced by generic conversion traits"]
|
147 |
| -pub trait AsciiCast<T, U = Self> for Sized?: AsciiExt<U> { |
| 149 | +pub trait AsciiCast<T, U = Self> : AsciiExt<U> { |
148 | 150 | /// Convert to an ascii type, return Err(()) on non-ASCII input.
|
149 | 151 | #[inline]
|
150 | 152 | fn to_ascii(&self) -> Result<T, ()> {
|
@@ -193,7 +195,7 @@ impl AsciiCast<Ascii> for char {
|
193 | 195 |
|
194 | 196 | /// Trait for copyless casting to an ascii vector.
|
195 | 197 | #[experimental = "may be replaced by generic conversion traits"]
|
196 |
| -pub trait OwnedAsciiCast<Sized? T, U = Self> |
| 198 | +pub trait OwnedAsciiCast<T: ?Sized, U = Self> : Sized |
197 | 199 | where T: BorrowFrom<Self> + AsciiExt<U> {
|
198 | 200 | /// Take ownership and cast to an ascii vector. Return Err(()) on non-ASCII input.
|
199 | 201 | #[inline]
|
@@ -236,10 +238,17 @@ impl OwnedAsciiCast<[u8]> for Vec<u8> {
|
236 | 238 | }
|
237 | 239 | }
|
238 | 240 |
|
| 241 | +/// Trait for converting a type to a string, consuming it in the process. |
| 242 | +#[experimental = "may be replaced by generic conversion traits"] |
| 243 | +pub trait IntoString { |
| 244 | + /// Consume and convert to a string. |
| 245 | + fn into_string(self) -> String; |
| 246 | +} |
| 247 | + |
239 | 248 | /// Trait for converting an ascii type to a string. Needed to convert
|
240 | 249 | /// `&[Ascii]` to `&str`.
|
241 | 250 | #[experimental = "may be replaced by generic conversion traits"]
|
242 |
| -pub trait AsciiStr for Sized? { |
| 251 | +pub trait AsciiStr { |
243 | 252 | /// Convert to a string.
|
244 | 253 | fn as_str<'a>(&'a self) -> &'a str;
|
245 | 254 |
|
|
0 commit comments