mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
Auto merge of #9684 - danlrobertson:i9655, r=KiChjang
Add methods to move ByteStrings underlying bytes Add methods to move the underlying `Vec<u8>` for `ByteString`. I saw this as at least two methods. One to "move and replace with and empty Vec<u8> (`bytes`), and one to take ownership of the whole object (`own_bytes`). I typically also don't like adding methods with out unit tests. If you think they're unnecessary, just let me know. As always, please let me know if you have any comments, critiques, or nits! Fixes #9655 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9684) <!-- Reviewable:end -->
This commit is contained in:
commit
aae6525f7d
4 changed files with 36 additions and 9 deletions
17
tests/unit/script/dom/bindings.rs
Normal file
17
tests/unit/script/dom/bindings.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use script::dom::bindings::str::ByteString;
|
||||
|
||||
#[test]
|
||||
fn test_byte_string_move() {
|
||||
let mut byte_str = ByteString::new(vec![0x73, 0x65, 0x72, 0x76, 0x6f]);
|
||||
let mut byte_vec = byte_str.bytes();
|
||||
|
||||
assert_eq!(byte_vec, "servo".as_bytes());
|
||||
assert_eq!(*byte_str, []);
|
||||
|
||||
byte_vec = byte_str.into();
|
||||
assert_eq!(byte_vec, Vec::new());
|
||||
}
|
|
@ -9,5 +9,6 @@ extern crate util;
|
|||
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
|
||||
#[cfg(test)] mod textinput;
|
||||
#[cfg(test)] mod dom {
|
||||
mod bindings;
|
||||
mod blob;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue