Bug 1377351 - Part 3: Expose nsA[C]String::Assign(nsA[C]String&&) overload as take_from to rust, r=froydnj

MozReview-Commit-ID: 4YNPi3iRo78
This commit is contained in:
Nika Layzell 2017-10-02 10:58:18 -04:00
Родитель 2ff829eabc
Коммит 4146e6b110
2 изменённых файлов: 46 добавлений и 0 удалений

Просмотреть файл

@ -179,6 +179,7 @@ macro_rules! define_string_types {
drop = $drop: ident;
assign = $assign: ident, $fallible_assign: ident;
take_from = $take_from: ident, $fallible_take_from: ident;
append = $append: ident, $fallible_append: ident;
set_length = $set_length: ident, $fallible_set_length: ident;
begin_writing = $begin_writing: ident, $fallible_begin_writing: ident;
@ -270,6 +271,25 @@ macro_rules! define_string_types {
}
}
/// Take the value of `other` and set `self`, overwriting any value
/// currently stored. The passed-in string will be truncated.
pub fn take_from(&mut self, other: &mut $AString) {
unsafe { $take_from(self, other) };
}
/// Take the value of `other` and set `self`, overwriting any value
/// currently stored. If this function fails, the source string will
/// be left untouched, otherwise it will be truncated.
///
/// Returns Ok(()) on success, and Err(()) if the allocation failed.
pub fn fallible_take_from(&mut self, other: &mut $AString) -> Result<(), ()> {
if unsafe { $fallible_take_from(self, other) } {
Ok(())
} else {
Err(())
}
}
/// Append the value of `other` into self.
pub fn append<T: $StringLike + ?Sized>(&mut self, other: &T) {
unsafe { $append(self, other.adapt().as_ptr()) };
@ -776,6 +796,7 @@ define_string_types! {
drop = Gecko_FinalizeCString;
assign = Gecko_AssignCString, Gecko_FallibleAssignCString;
take_from = Gecko_TakeFromCString, Gecko_FallibleTakeFromCString;
append = Gecko_AppendCString, Gecko_FallibleAppendCString;
set_length = Gecko_SetLengthCString, Gecko_FallibleSetLengthCString;
begin_writing = Gecko_BeginWritingCString, Gecko_FallibleBeginWritingCString;
@ -909,6 +930,7 @@ define_string_types! {
drop = Gecko_FinalizeString;
assign = Gecko_AssignString, Gecko_FallibleAssignString;
take_from = Gecko_TakeFromString, Gecko_FallibleTakeFromString;
append = Gecko_AppendString, Gecko_FallibleAppendString;
set_length = Gecko_SetLengthString, Gecko_FallibleSetLengthString;
begin_writing = Gecko_BeginWritingString, Gecko_FallibleBeginWritingString;
@ -994,10 +1016,12 @@ extern "C" {
fn Gecko_FinalizeCString(this: *mut nsACString);
fn Gecko_AssignCString(this: *mut nsACString, other: *const nsACString);
fn Gecko_TakeFromCString(this: *mut nsACString, other: *mut nsACString);
fn Gecko_AppendCString(this: *mut nsACString, other: *const nsACString);
fn Gecko_SetLengthCString(this: *mut nsACString, length: u32);
fn Gecko_BeginWritingCString(this: *mut nsACString) -> *mut u8;
fn Gecko_FallibleAssignCString(this: *mut nsACString, other: *const nsACString) -> bool;
fn Gecko_FallibleTakeFromCString(this: *mut nsACString, other: *mut nsACString) -> bool;
fn Gecko_FallibleAppendCString(this: *mut nsACString, other: *const nsACString) -> bool;
fn Gecko_FallibleSetLengthCString(this: *mut nsACString, length: u32) -> bool;
fn Gecko_FallibleBeginWritingCString(this: *mut nsACString) -> *mut u8;
@ -1005,10 +1029,12 @@ extern "C" {
fn Gecko_FinalizeString(this: *mut nsAString);
fn Gecko_AssignString(this: *mut nsAString, other: *const nsAString);
fn Gecko_TakeFromString(this: *mut nsAString, other: *mut nsAString);
fn Gecko_AppendString(this: *mut nsAString, other: *const nsAString);
fn Gecko_SetLengthString(this: *mut nsAString, length: u32);
fn Gecko_BeginWritingString(this: *mut nsAString) -> *mut u16;
fn Gecko_FallibleAssignString(this: *mut nsAString, other: *const nsAString) -> bool;
fn Gecko_FallibleTakeFromString(this: *mut nsAString, other: *mut nsAString) -> bool;
fn Gecko_FallibleAppendString(this: *mut nsAString, other: *const nsAString) -> bool;
fn Gecko_FallibleSetLengthString(this: *mut nsAString, length: u32) -> bool;
fn Gecko_FallibleBeginWritingString(this: *mut nsAString) -> *mut u16;

Просмотреть файл

@ -380,6 +380,11 @@ void Gecko_AssignCString(nsACString* aThis, const nsACString* aOther)
aThis->Assign(*aOther);
}
void Gecko_TakeFromCString(nsACString* aThis, nsACString* aOther)
{
aThis->Assign(mozilla::Move(*aOther));
}
void Gecko_AppendCString(nsACString* aThis, const nsACString* aOther)
{
aThis->Append(*aOther);
@ -395,6 +400,11 @@ bool Gecko_FallibleAssignCString(nsACString* aThis, const nsACString* aOther)
return aThis->Assign(*aOther, mozilla::fallible);
}
bool Gecko_FallibleTakeFromCString(nsACString* aThis, nsACString* aOther)
{
return aThis->Assign(mozilla::Move(*aOther), mozilla::fallible);
}
bool Gecko_FallibleAppendCString(nsACString* aThis, const nsACString* aOther)
{
return aThis->Append(*aOther, mozilla::fallible);
@ -425,6 +435,11 @@ void Gecko_AssignString(nsAString* aThis, const nsAString* aOther)
aThis->Assign(*aOther);
}
void Gecko_TakeFromString(nsAString* aThis, nsAString* aOther)
{
aThis->Assign(mozilla::Move(*aOther));
}
void Gecko_AppendString(nsAString* aThis, const nsAString* aOther)
{
aThis->Append(*aOther);
@ -440,6 +455,11 @@ bool Gecko_FallibleAssignString(nsAString* aThis, const nsAString* aOther)
return aThis->Assign(*aOther, mozilla::fallible);
}
bool Gecko_FallibleTakeFromString(nsAString* aThis, nsAString* aOther)
{
return aThis->Assign(mozilla::Move(*aOther), mozilla::fallible);
}
bool Gecko_FallibleAppendString(nsAString* aThis, const nsAString* aOther)
{
return aThis->Append(*aOther, mozilla::fallible);