mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +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
|
@ -400,9 +400,8 @@ impl FromJSValConvertible for USVString {
|
|||
impl ToJSValConvertible for ByteString {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
unsafe {
|
||||
let slice = self.as_slice();
|
||||
let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *const libc::c_char,
|
||||
slice.len() as libc::size_t);
|
||||
let jsstr = JS_NewStringCopyN(cx, self.as_ptr() as *const libc::c_char,
|
||||
self.len() as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
panic!("JS_NewStringCopyN failed");
|
||||
}
|
||||
|
|
|
@ -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