mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Replace ByteString::as_slice() by a Deref implementation.
This commit is contained in:
parent
0a5ffc4bb0
commit
84b1b52682
3 changed files with 14 additions and 13 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue