From 8679f8c90409b75e5e0b87e234851e70c76ad9cb Mon Sep 17 00:00:00 2001 From: Daniel Ralston Date: Fri, 3 May 2013 02:33:51 -0700 Subject: [PATCH] Implement ToStr for char cc #6133 --- src/libcore/char.rs | 7 +++++++ src/test/run-pass/char_to_str.rs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/test/run-pass/char_to_str.rs diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 7868b463807f6..b03a1ef683054 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -14,6 +14,7 @@ use cmp::Ord; use option::{None, Option, Some}; use str; +use to_str::ToStr; use u32; use uint; use unicode; @@ -265,6 +266,12 @@ impl Ord for char { fn ge(&self, other: &char) -> bool { *self >= *other } } +impl ToStr for char { + fn to_str(&self) -> ~str { + str::from_char(*self) + } +} + #[test] fn test_is_lowercase() { assert!(is_lowercase('a')); diff --git a/src/test/run-pass/char_to_str.rs b/src/test/run-pass/char_to_str.rs new file mode 100644 index 0000000000000..8a5170678f516 --- /dev/null +++ b/src/test/run-pass/char_to_str.rs @@ -0,0 +1,18 @@ +// Copyright 2013 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +// Regression test for #6133 + +use core::cmp::Equiv; + +pub fn main() { + assert!("c".equiv(&'c'.to_str())); +}