Rust API guideline: no get_ prefix

master
Jos van den Oever 2017-08-31 09:01:14 +02:00
parent 9d2cd5ba08
commit 17f7bfdaa0
13 changed files with 53 additions and 53 deletions

View File

@ -38,7 +38,7 @@ impl FibonacciTrait for Fibonacci {
fn emit(&self) -> &FibonacciEmitter {
&self.emit
}
fn get_input(&self) -> u32 {
fn input(&self) -> u32 {
self.input
}
fn set_input(&mut self, value: u32) {
@ -54,7 +54,7 @@ impl FibonacciTrait for Fibonacci {
emit.result_changed();
});
}
fn get_result(&self) -> u64 {
fn result(&self) -> u64 {
self.result.fetch_add(0, Ordering::SeqCst) as u64
}
}

View File

@ -80,9 +80,9 @@ impl FibonacciEmitter {
pub trait FibonacciTrait {
fn create(emit: FibonacciEmitter) -> Self;
fn emit(&self) -> &FibonacciEmitter;
fn get_input(&self) -> u32;
fn input(&self) -> u32;
fn set_input(&mut self, value: u32);
fn get_result(&self) -> u64;
fn result(&self) -> u64;
}
#[no_mangle]
@ -107,7 +107,7 @@ pub unsafe extern "C" fn fibonacci_free(ptr: *mut Fibonacci) {
#[no_mangle]
pub unsafe extern "C" fn fibonacci_input_get(ptr: *const Fibonacci) -> u32 {
(&*ptr).get_input()
(&*ptr).input()
}
#[no_mangle]
@ -117,7 +117,7 @@ pub unsafe extern "C" fn fibonacci_input_set(ptr: *mut Fibonacci, v: u32) {
#[no_mangle]
pub unsafe extern "C" fn fibonacci_result_get(ptr: *const Fibonacci) -> u64 {
(&*ptr).get_result()
(&*ptr).result()
}
pub struct FibonacciListQObject {}

View File

@ -203,7 +203,7 @@ where
fn emit(&self) -> &TreeEmitter {
&self.emit
}
fn get_path(&self) -> Option<&str> {
fn path(&self) -> Option<&str> {
self.path.as_ref().map(|s|&s[..])
}
fn set_path(&mut self, value: Option<String>) {

View File

@ -176,7 +176,7 @@ impl TreeUniformTree {
pub trait TreeTrait {
fn create(emit: TreeEmitter, model: TreeUniformTree) -> Self;
fn emit(&self) -> &TreeEmitter;
fn get_path(&self) -> Option<&str>;
fn path(&self) -> Option<&str>;
fn set_path(&mut self, value: Option<String>);
fn row_count(&self, Option<usize>) -> usize;
fn can_fetch_more(&self, Option<usize>) -> bool {
@ -238,7 +238,7 @@ pub unsafe extern "C" fn tree_path_get(
p: *mut c_void,
set: fn(*mut c_void, QString),
) {
let data = (&*ptr).get_path();
let data = (&*ptr).path();
if let Some(data) = data {
set(p, data.into());
}

View File

@ -367,7 +367,7 @@ impl ProcessesTrait for Processes {
fn cmd(&self, item: usize) -> String {
self.process(item).cmd.join(" ")
}
fn get_active(&self) -> bool {
fn active(&self) -> bool {
self.active
}
fn set_active(&mut self, active: bool) {

View File

@ -153,7 +153,7 @@ impl ProcessesUniformTree {
pub trait ProcessesTrait {
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Self;
fn emit(&self) -> &ProcessesEmitter;
fn get_active(&self) -> bool;
fn active(&self) -> bool;
fn set_active(&mut self, value: bool);
fn row_count(&self, Option<usize>) -> usize;
fn can_fetch_more(&self, Option<usize>) -> bool {
@ -212,7 +212,7 @@ pub unsafe extern "C" fn processes_free(ptr: *mut Processes) {
#[no_mangle]
pub unsafe extern "C" fn processes_active_get(ptr: *const Processes) -> bool {
(&*ptr).get_active()
(&*ptr).active()
}
#[no_mangle]

View File

@ -251,10 +251,10 @@ pub trait %1Trait {
for (const Property& p: o.properties) {
const QString lc(snakeCase(p.name));
if (p.type.type == BindingType::Object) {
r << QString(" fn get_%1(&self) -> &%2;\n").arg(lc, rustType(p));
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));
} else {
r << QString(" fn get_%1(&self) -> %2;\n").arg(lc, rustReturnType(p));
r << QString(" fn %1(&self) -> %2;\n").arg(lc, rustReturnType(p));
if (p.write) {
r << QString(" fn set_%1(&mut self, value: %2);\n").arg(lc, rustType(p));
}
@ -326,7 +326,7 @@ pub unsafe extern "C" fn %2_get(
p: *mut c_void,
set: fn(*mut c_void, %4),
) {
let data = (&*ptr).get_%3();
let data = (&*ptr).%3();
set(p, %5data.into());
}
)").arg(o.name, base, snakeCase(p.name), p.type.name,
@ -348,7 +348,7 @@ pub unsafe extern "C" fn %2_get(
p: *mut c_void,
set: fn(*mut c_void, %4),
) {
let data = (&*ptr).get_%3();
let data = (&*ptr).%3();
if let Some(data) = data {
set(p, %5data.into());
}
@ -372,7 +372,7 @@ pub unsafe extern "C" fn %2_set_none(ptr: *mut %1) {
r << QString(R"(
#[no_mangle]
pub unsafe extern "C" fn %2_get(ptr: *const %1) -> %4 {
(&*ptr).get_%3()
(&*ptr).%3()
}
)").arg(o.name, base, snakeCase(p.name), rustType(p));
if (p.write) {
@ -785,7 +785,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
for (const Property& p: o.properties) {
const QString lc(snakeCase(p.name));
if (p.type.type == BindingType::Object) {
r << QString(R"( fn get_%1(&self) -> &%2 {
r << QString(R"( fn %1(&self) -> &%2 {
&self.%1
}
fn get_mut_%1(&mut self) -> &mut %2 {
@ -793,7 +793,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
}
)").arg(lc, rustReturnType(p));
} else {
r << QString(" fn get_%1(&self) -> %2 {\n").arg(lc, rustReturnType(p));
r << QString(" fn %1(&self) -> %2 {\n").arg(lc, rustReturnType(p));
if (p.type.isComplex()) {
if (p.optional) {
/*

View File

@ -18,7 +18,7 @@ impl PersonTrait for Person {
fn emit(&self) -> &PersonEmitter {
&self.emit
}
fn get_user_name(&self) -> &str {
fn user_name(&self) -> &str {
&self.user_name
}
fn set_user_name(&mut self, value: String) {

View File

@ -72,7 +72,7 @@ impl PersonEmitter {
pub trait PersonTrait {
fn create(emit: PersonEmitter) -> Self;
fn emit(&self) -> &PersonEmitter;
fn get_user_name(&self) -> &str;
fn user_name(&self) -> &str;
fn set_user_name(&mut self, value: String);
}
@ -100,7 +100,7 @@ pub unsafe extern "C" fn person_user_name_get(
p: *mut c_void,
set: fn(*mut c_void, QString),
) {
let data = (&*ptr).get_user_name();
let data = (&*ptr).user_name();
set(p, data.into());
}

View File

@ -32,56 +32,56 @@ impl ObjectTrait for Object {
fn emit(&self) -> &ObjectEmitter {
&self.emit
}
fn get_boolean(&self) -> bool {
fn boolean(&self) -> bool {
self.boolean
}
fn set_boolean(&mut self, value: bool) {
self.boolean = value;
self.emit.boolean_changed();
}
fn get_bytearray(&self) -> &[u8] {
fn bytearray(&self) -> &[u8] {
&self.bytearray
}
fn set_bytearray(&mut self, value: Vec<u8>) {
self.bytearray = value;
self.emit.bytearray_changed();
}
fn get_integer(&self) -> i32 {
fn integer(&self) -> i32 {
self.integer
}
fn set_integer(&mut self, value: i32) {
self.integer = value;
self.emit.integer_changed();
}
fn get_optional_bytearray(&self) -> Option<&[u8]> {
fn optional_bytearray(&self) -> Option<&[u8]> {
self.optional_bytearray.as_ref().map(|p|&p[..])
}
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>) {
self.optional_bytearray = value;
self.emit.optional_bytearray_changed();
}
fn get_optional_string(&self) -> Option<&str> {
fn optional_string(&self) -> Option<&str> {
self.optional_string.as_ref().map(|p|&p[..])
}
fn set_optional_string(&mut self, value: Option<String>) {
self.optional_string = value;
self.emit.optional_string_changed();
}
fn get_string(&self) -> &str {
fn string(&self) -> &str {
&self.string
}
fn set_string(&mut self, value: String) {
self.string = value;
self.emit.string_changed();
}
fn get_u64(&self) -> u64 {
fn u64(&self) -> u64 {
self.u64
}
fn set_u64(&mut self, value: u64) {
self.u64 = value;
self.emit.u64_changed();
}
fn get_uinteger(&self) -> u32 {
fn uinteger(&self) -> u32 {
self.uinteger
}
fn set_uinteger(&mut self, value: u32) {

View File

@ -170,21 +170,21 @@ impl ObjectEmitter {
pub trait ObjectTrait {
fn create(emit: ObjectEmitter) -> Self;
fn emit(&self) -> &ObjectEmitter;
fn get_boolean(&self) -> bool;
fn boolean(&self) -> bool;
fn set_boolean(&mut self, value: bool);
fn get_bytearray(&self) -> &[u8];
fn bytearray(&self) -> &[u8];
fn set_bytearray(&mut self, value: Vec<u8>);
fn get_integer(&self) -> i32;
fn integer(&self) -> i32;
fn set_integer(&mut self, value: i32);
fn get_optional_bytearray(&self) -> Option<&[u8]>;
fn optional_bytearray(&self) -> Option<&[u8]>;
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>);
fn get_optional_string(&self) -> Option<&str>;
fn optional_string(&self) -> Option<&str>;
fn set_optional_string(&mut self, value: Option<String>);
fn get_string(&self) -> &str;
fn string(&self) -> &str;
fn set_string(&mut self, value: String);
fn get_u64(&self) -> u64;
fn u64(&self) -> u64;
fn set_u64(&mut self, value: u64);
fn get_uinteger(&self) -> u32;
fn uinteger(&self) -> u32;
fn set_uinteger(&mut self, value: u32);
}
@ -222,7 +222,7 @@ pub unsafe extern "C" fn object_free(ptr: *mut Object) {
#[no_mangle]
pub unsafe extern "C" fn object_boolean_get(ptr: *const Object) -> bool {
(&*ptr).get_boolean()
(&*ptr).boolean()
}
#[no_mangle]
@ -236,7 +236,7 @@ pub unsafe extern "C" fn object_bytearray_get(
p: *mut c_void,
set: fn(*mut c_void, QByteArray),
) {
let data = (&*ptr).get_bytearray();
let data = (&*ptr).bytearray();
set(p, data.into());
}
@ -247,7 +247,7 @@ pub unsafe extern "C" fn object_bytearray_set(ptr: *mut Object, v: QByteArray) {
#[no_mangle]
pub unsafe extern "C" fn object_integer_get(ptr: *const Object) -> i32 {
(&*ptr).get_integer()
(&*ptr).integer()
}
#[no_mangle]
@ -261,7 +261,7 @@ pub unsafe extern "C" fn object_optional_bytearray_get(
p: *mut c_void,
set: fn(*mut c_void, QByteArray),
) {
let data = (&*ptr).get_optional_bytearray();
let data = (&*ptr).optional_bytearray();
if let Some(data) = data {
set(p, data.into());
}
@ -282,7 +282,7 @@ pub unsafe extern "C" fn object_optional_string_get(
p: *mut c_void,
set: fn(*mut c_void, QString),
) {
let data = (&*ptr).get_optional_string();
let data = (&*ptr).optional_string();
if let Some(data) = data {
set(p, data.into());
}
@ -303,7 +303,7 @@ pub unsafe extern "C" fn object_string_get(
p: *mut c_void,
set: fn(*mut c_void, QString),
) {
let data = (&*ptr).get_string();
let data = (&*ptr).string();
set(p, data.into());
}
@ -314,7 +314,7 @@ pub unsafe extern "C" fn object_string_set(ptr: *mut Object, v: QStringIn) {
#[no_mangle]
pub unsafe extern "C" fn object_u64_get(ptr: *const Object) -> u64 {
(&*ptr).get_u64()
(&*ptr).u64()
}
#[no_mangle]
@ -324,7 +324,7 @@ pub unsafe extern "C" fn object_u64_set(ptr: *mut Object, v: u64) {
#[no_mangle]
pub unsafe extern "C" fn object_uinteger_get(ptr: *const Object) -> u32 {
(&*ptr).get_uinteger()
(&*ptr).uinteger()
}
#[no_mangle]

View File

@ -18,7 +18,7 @@ impl GroupTrait for Group {
fn emit(&self) -> &GroupEmitter {
&self.emit
}
fn get_person(&self) -> &Person {
fn person(&self) -> &Person {
&self.person
}
fn get_mut_person(&mut self) -> &mut Person {
@ -41,7 +41,7 @@ impl InnerObjectTrait for InnerObject {
fn emit(&self) -> &InnerObjectEmitter {
&self.emit
}
fn get_description(&self) -> &str {
fn description(&self) -> &str {
&self.description
}
fn set_description(&mut self, value: String) {
@ -65,7 +65,7 @@ impl PersonTrait for Person {
fn emit(&self) -> &PersonEmitter {
&self.emit
}
fn get_object(&self) -> &InnerObject {
fn object(&self) -> &InnerObject {
&self.object
}
fn get_mut_object(&mut self) -> &mut InnerObject {

View File

@ -66,7 +66,7 @@ pub trait GroupTrait {
fn create(emit: GroupEmitter,
person: Person) -> Self;
fn emit(&self) -> &GroupEmitter;
fn get_person(&self) -> &Person;
fn person(&self) -> &Person;
fn get_mut_person(&mut self) -> &mut Person;
}
@ -130,7 +130,7 @@ impl InnerObjectEmitter {
pub trait InnerObjectTrait {
fn create(emit: InnerObjectEmitter) -> Self;
fn emit(&self) -> &InnerObjectEmitter;
fn get_description(&self) -> &str;
fn description(&self) -> &str;
fn set_description(&mut self, value: String);
}
@ -158,7 +158,7 @@ pub unsafe extern "C" fn inner_object_description_get(
p: *mut c_void,
set: fn(*mut c_void, QString),
) {
let data = (&*ptr).get_description();
let data = (&*ptr).description();
set(p, data.into());
}
@ -186,7 +186,7 @@ pub trait PersonTrait {
fn create(emit: PersonEmitter,
object: InnerObject) -> Self;
fn emit(&self) -> &PersonEmitter;
fn get_object(&self) -> &InnerObject;
fn object(&self) -> &InnerObject;
fn get_mut_object(&mut self) -> &mut InnerObject;
}