Replace ByteString::as_slice() by a Deref implementation.

This commit is contained in:
Ms2ger 2015-05-01 21:19:11 +02:00
parent 0a5ffc4bb0
commit 84b1b52682
3 changed files with 14 additions and 13 deletions

View file

@ -6,6 +6,7 @@
use std::borrow::ToOwned;
use std::hash::{Hash, Hasher};
use std::ops;
use std::str;
use std::str::FromStr;
@ -27,12 +28,6 @@ impl ByteString {
str::from_utf8(&vec).ok()
}
/// Returns the underlying vector as a slice.
pub fn as_slice<'a>(&'a self) -> &'a [u8] {
let ByteString(ref vector) = *self;
vector
}
/// Returns the length.
pub fn len(&self) -> usize {
let ByteString(ref vector) = *self;
@ -158,6 +153,13 @@ impl FromStr for ByteString {
}
}
impl ops::Deref for ByteString {
type Target = [u8];
fn deref(&self) -> &[u8] {
&self.0
}
}
/// A string that is constructed from a UCS-2 buffer by replacing invalid code
/// points with the replacement character.
pub struct USVString(pub String);