Rust API guideline: no _mut suffix instead of get_mut_ prefix

master
Jos van den Oever 2017-08-31 09:02:56 +02:00
parent 17f7bfdaa0
commit 631f96d350
3 changed files with 9 additions and 9 deletions

View File

@ -252,7 +252,7 @@ pub trait %1Trait {
const QString lc(snakeCase(p.name));
if (p.type.type == BindingType::Object) {
r << QString(" fn %1(&self) -> &%2;\n").arg(lc, rustType(p));
r << QString(" fn get_mut_%1(&mut self) -> &mut %2;\n").arg(lc, rustType(p));
r << QString(" fn %1_mut(&mut self) -> &mut %2;\n").arg(lc, rustType(p));
} else {
r << QString(" fn %1(&self) -> %2;\n").arg(lc, rustReturnType(p));
if (p.write) {
@ -314,7 +314,7 @@ pub unsafe extern "C" fn %2_free(ptr: *mut %1) {
r << QString(R"(
#[no_mangle]
pub unsafe extern "C" fn %2_get(ptr: *mut %1) -> *mut %4 {
(&mut *ptr).get_mut_%3()
(&mut *ptr).%3_mut()
}
)").arg(o.name, base, snakeCase(p.name), rustType(p));
@ -788,7 +788,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
r << QString(R"( fn %1(&self) -> &%2 {
&self.%1
}
fn get_mut_%1(&mut self) -> &mut %2 {
fn %1_mut(&mut self) -> &mut %2 {
&mut self.%1
}
)").arg(lc, rustReturnType(p));

View File

@ -21,7 +21,7 @@ impl GroupTrait for Group {
fn person(&self) -> &Person {
&self.person
}
fn get_mut_person(&mut self) -> &mut Person {
fn person_mut(&mut self) -> &mut Person {
&mut self.person
}
}
@ -68,7 +68,7 @@ impl PersonTrait for Person {
fn object(&self) -> &InnerObject {
&self.object
}
fn get_mut_object(&mut self) -> &mut InnerObject {
fn object_mut(&mut self) -> &mut InnerObject {
&mut self.object
}
}

View File

@ -67,7 +67,7 @@ pub trait GroupTrait {
person: Person) -> Self;
fn emit(&self) -> &GroupEmitter;
fn person(&self) -> &Person;
fn get_mut_person(&mut self) -> &mut Person;
fn person_mut(&mut self) -> &mut Person;
}
#[no_mangle]
@ -102,7 +102,7 @@ pub unsafe extern "C" fn group_free(ptr: *mut Group) {
#[no_mangle]
pub unsafe extern "C" fn group_person_get(ptr: *mut Group) -> *mut Person {
(&mut *ptr).get_mut_person()
(&mut *ptr).person_mut()
}
pub struct InnerObjectQObject {}
@ -187,7 +187,7 @@ pub trait PersonTrait {
object: InnerObject) -> Self;
fn emit(&self) -> &PersonEmitter;
fn object(&self) -> &InnerObject;
fn get_mut_object(&mut self) -> &mut InnerObject;
fn object_mut(&mut self) -> &mut InnerObject;
}
#[no_mangle]
@ -216,5 +216,5 @@ pub unsafe extern "C" fn person_free(ptr: *mut Person) {
#[no_mangle]
pub unsafe extern "C" fn person_object_get(ptr: *mut Person) -> *mut InnerObject {
(&mut *ptr).get_mut_object()
(&mut *ptr).object_mut()
}