зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1316964 - Make the append and assign methods on the rust nsstring types more generic, r=froydnj
MozReview-Commit-ID: 5y30BnUDKsT
This commit is contained in:
Родитель
7fe406a0e5
Коммит
fb03faf0e0
|
@ -258,6 +258,12 @@ macro_rules! define_string_types {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsRef<[$char_t]> for $AString {
|
||||
fn as_ref(&self) -> &[$char_t] {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl cmp::PartialEq for $AString {
|
||||
fn eq(&self, other: &$AString) -> bool {
|
||||
&self[..] == &other[..]
|
||||
|
@ -313,6 +319,12 @@ macro_rules! define_string_types {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRef<[$char_t]> for $String<'a> {
|
||||
fn as_ref(&self) -> &[$char_t] {
|
||||
&self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a String> for $String<'a> {
|
||||
fn from(s: &'a String) -> $String<'a> {
|
||||
$String::from(&s[..])
|
||||
|
@ -472,6 +484,12 @@ macro_rules! define_string_types {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRef<[$char_t]> for $FixedString<'a> {
|
||||
fn as_ref(&self) -> &[$char_t] {
|
||||
&self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Write for $FixedString<'a> {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
||||
$AString::write_str(self, s)
|
||||
|
@ -554,26 +572,29 @@ impl nsACString {
|
|||
Gecko_FinalizeCString(self);
|
||||
}
|
||||
|
||||
pub fn assign(&mut self, other: &nsACString) {
|
||||
pub fn assign<T: AsRef<[u8]>>(&mut self, other: &T) {
|
||||
let s = nsCString::from(other.as_ref());
|
||||
unsafe {
|
||||
Gecko_AssignCString(self as *mut _, other as *const _);
|
||||
Gecko_AssignCString(self, &*s);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assign_utf16(&mut self, other: &nsAString) {
|
||||
self.assign(&nsCString::new());
|
||||
pub fn assign_utf16<T: AsRef<[u16]>>(&mut self, other: &T) {
|
||||
self.assign(&[]);
|
||||
self.append_utf16(other);
|
||||
}
|
||||
|
||||
pub fn append(&mut self, other: &nsACString) {
|
||||
pub fn append<T: AsRef<[u8]>>(&mut self, other: &T) {
|
||||
let s = nsCString::from(other.as_ref());
|
||||
unsafe {
|
||||
Gecko_AppendCString(self as *mut _, other as *const _);
|
||||
Gecko_AppendCString(self, &*s);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append_utf16(&mut self, other: &nsAString) {
|
||||
pub fn append_utf16<T: AsRef<[u16]>>(&mut self, other: &T) {
|
||||
let s = nsString::from(other.as_ref());
|
||||
unsafe {
|
||||
Gecko_AppendUTF16toCString(self as *mut _, other as *const _);
|
||||
Gecko_AppendUTF16toCString(self, &*s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -658,26 +679,29 @@ impl nsAString {
|
|||
Gecko_FinalizeString(self);
|
||||
}
|
||||
|
||||
pub fn assign(&mut self, other: &nsAString) {
|
||||
pub fn assign<T: AsRef<[u16]>>(&mut self, other: &T) {
|
||||
let s = nsString::from(other.as_ref());
|
||||
unsafe {
|
||||
Gecko_AssignString(self as *mut _, other as *const _);
|
||||
Gecko_AssignString(self, &*s);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assign_utf8(&mut self, other: &nsACString) {
|
||||
self.assign(&nsString::new());
|
||||
pub fn assign_utf8<T: AsRef<[u8]>>(&mut self, other: &T) {
|
||||
self.assign(&[]);
|
||||
self.append_utf8(other);
|
||||
}
|
||||
|
||||
pub fn append(&mut self, other: &nsAString) {
|
||||
pub fn append<T: AsRef<[u16]>>(&mut self, other: &T) {
|
||||
let s = nsString::from(other.as_ref());
|
||||
unsafe {
|
||||
Gecko_AppendString(self as *mut _, other as *const _);
|
||||
Gecko_AppendString(self, &*s);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append_utf8(&mut self, other: &nsACString) {
|
||||
pub fn append_utf8<T: AsRef<[u8]>>(&mut self, other: &T) {
|
||||
let s = nsCString::from(other.as_ref());
|
||||
unsafe {
|
||||
Gecko_AppendUTF8toString(self as *mut _, other as *const _);
|
||||
Gecko_AppendUTF8toString(self, &*s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче