Skip to content

Commit

Permalink
ref: remove warnings
Browse files Browse the repository at this point in the history
1.Use camel case instead of underscores for type names
2.for functions and variables never used comment out
3.for field never be read or enum never be constructed add underscore
4.there is another warning which is 'unnecessary `unsafe` block' seems like a Incorrect warning: rust-lang/rust#49112
  • Loading branch information
lispQin committed Feb 17, 2023
1 parent 48f4f87 commit cf812f8
Show file tree
Hide file tree
Showing 19 changed files with 405 additions and 404 deletions.
2 changes: 1 addition & 1 deletion taos-optin/src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl RawTaos {
pub fn query_a<'a, S: IntoCStr<'a>>(
&self,
sql: S,
fp: taos_async_query_cb,
fp: TaosAsyncQueryCb,
param: *mut c_void,
) {
unsafe { taos_query_a(self.as_ptr(), sql.into_c_str().as_ptr(), fp, param) }
Expand Down
104 changes: 52 additions & 52 deletions taos-optin/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,147 +49,147 @@ extern "C" {


extern "C" {
pub fn taos_fetch_rows_a(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void);
pub fn taos_fetch_rows_a(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void);

pub fn taos_query_a(
taos: *mut TAOS,
sql: *const c_char,
fp: taos_async_query_cb,
fp: TaosAsyncQueryCb,
param: *mut c_void,
);
}

extern "C" {
pub fn taos_load_table_info(taos: *mut TAOS, tableNameList: *const c_char) -> c_int;

pub fn taos_stmt_init(taos: *mut TAOS) -> *mut TAOS_STMT;
pub fn taos_stmt_init(taos: *mut TAOS) -> *mut TaosStmt;

pub fn taos_stmt_prepare(stmt: *mut TAOS_STMT, sql: *const c_char, length: c_ulong) -> c_int;
pub fn taos_stmt_prepare(stmt: *mut TaosStmt, sql: *const c_char, length: c_ulong) -> c_int;

pub fn taos_stmt_set_tbname_tags(
stmt: *mut TAOS_STMT,
stmt: *mut TaosStmt,
name: *const c_char,
tags: *mut TaosBind,
) -> c_int;

pub fn taos_stmt_set_tbname(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int;
pub fn taos_stmt_set_tbname(stmt: *mut TaosStmt, name: *const c_char) -> c_int;

pub fn taos_stmt_set_tags(stmt: *mut TAOS_STMT, tags: *mut TaosBind) -> c_int;
pub fn taos_stmt_set_tags(stmt: *mut TaosStmt, tags: *mut TaosBind) -> c_int;

pub fn taos_stmt_set_sub_tbname(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int;
pub fn taos_stmt_set_sub_tbname(stmt: *mut TaosStmt, name: *const c_char) -> c_int;

pub fn taos_stmt_is_insert(stmt: *mut TAOS_STMT, insert: *mut c_int) -> c_int;
pub fn taos_stmt_is_insert(stmt: *mut TaosStmt, insert: *mut c_int) -> c_int;

pub fn taos_stmt_num_params(stmt: *mut TAOS_STMT, nums: *mut c_int) -> c_int;
pub fn taos_stmt_num_params(stmt: *mut TaosStmt, nums: *mut c_int) -> c_int;

pub fn taos_stmt_get_param(
stmt: *mut TAOS_STMT,
stmt: *mut TaosStmt,
idx: c_int,
type_: *mut c_int,
bytes: *mut c_int,
) -> c_int;

pub fn taos_stmt_bind_param(stmt: *mut TAOS_STMT, bind: *const TaosBind) -> c_int;
pub fn taos_stmt_bind_param(stmt: *mut TaosStmt, bind: *const TaosBind) -> c_int;

pub fn taos_stmt_bind_param_batch(stmt: *mut TAOS_STMT, bind: *const TaosMultiBind) -> c_int;
pub fn taos_stmt_bind_param_batch(stmt: *mut TaosStmt, bind: *const TaosMultiBind) -> c_int;

pub fn taos_stmt_bind_single_param_batch(
stmt: *mut TAOS_STMT,
stmt: *mut TaosStmt,
bind: *const TaosMultiBind,
colIdx: c_int,
) -> c_int;

pub fn taos_stmt_add_batch(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_add_batch(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_execute(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_execute(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_affected_rows(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_affected_rows(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_use_result(stmt: *mut TAOS_STMT) -> *mut TAOS_RES;
pub fn taos_stmt_use_result(stmt: *mut TaosStmt) -> *mut TaosRes;

pub fn taos_stmt_close(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_close(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_errstr(stmt: *mut TAOS_STMT) -> *const c_char;
pub fn taos_stmt_errstr(stmt: *mut TaosStmt) -> *const c_char;
}

extern "C" {
pub fn taos_query(taos: *mut TAOS, sql: *const c_char) -> *mut TAOS_RES;
pub fn taos_query(taos: *mut TAOS, sql: *const c_char) -> *mut TaosRes;

pub fn taos_fetch_row(res: *mut TAOS_RES) -> TAOS_ROW;
pub fn taos_fetch_row(res: *mut TaosRes) -> TaosRow;

pub fn taos_result_precision(res: *mut TAOS_RES) -> c_int;
pub fn taos_result_precision(res: *mut TaosRes) -> c_int;

pub fn taos_free_result(res: *mut TAOS_RES);
pub fn taos_free_result(res: *mut TaosRes);

pub fn taos_field_count(res: *mut TAOS_RES) -> c_int;
pub fn taos_field_count(res: *mut TaosRes) -> c_int;

pub fn taos_affected_rows(res: *mut TAOS_RES) -> c_int;
pub fn taos_affected_rows(res: *mut TaosRes) -> c_int;

pub fn taos_fetch_fields(res: *mut TAOS_RES) -> *mut TAOS_FIELD;
pub fn taos_fetch_fields(res: *mut TaosRes) -> *mut TAOS_FIELD;

pub fn taos_select_db(taos: *mut TAOS, db: *const c_char) -> c_int;

pub fn taos_print_row(
str_: *mut c_char,
row: TAOS_ROW,
row: TaosRow,
fields: *mut TAOS_FIELD,
num_fields: c_int,
) -> c_int;

pub fn taos_stop_query(res: *mut TAOS_RES);
pub fn taos_stop_query(res: *mut TaosRes);

pub fn taos_is_null(res: *mut TAOS_RES, row: i32, col: i32) -> bool;
pub fn taos_is_null(res: *mut TaosRes, row: i32, col: i32) -> bool;

pub fn taos_is_update_query(res: *mut TAOS_RES) -> bool;
pub fn taos_is_update_query(res: *mut TaosRes) -> bool;

pub fn taos_fetch_block(res: *mut TAOS_RES, rows: *mut TAOS_ROW) -> c_int;
pub fn taos_fetch_block(res: *mut TaosRes, rows: *mut TaosRow) -> c_int;

pub fn taos_fetch_lengths(res: *mut TAOS_RES) -> *mut c_int;
pub fn taos_fetch_lengths(res: *mut TaosRes) -> *mut c_int;

pub fn taos_validate_sql(taos: *mut TAOS, sql: *const c_char) -> c_int;

pub fn taos_reset_current_db(taos: *mut TAOS);

pub fn taos_get_server_info(taos: *mut TAOS) -> *mut c_char;

pub fn taos_errstr(tres: *mut TAOS_RES) -> *mut c_char;
pub fn taos_errstr(tres: *mut TaosRes) -> *mut c_char;

pub fn taos_errno(tres: *mut TAOS_RES) -> c_int;
pub fn taos_errno(tres: *mut TaosRes) -> c_int;

}

#[c_cfg(taos_v3)]
extern "C" {
pub fn taos_get_column_data_offset(res: *mut TAOS_RES, col: i32) -> *mut i32;
pub fn taos_get_column_data_offset(res: *mut TaosRes, col: i32) -> *mut i32;

pub fn taos_fetch_raw_block(res: *mut TAOS_RES, num: *mut i32, data: *mut *mut c_void)
pub fn taos_fetch_raw_block(res: *mut TaosRes, num: *mut i32, data: *mut *mut c_void)
-> c_int;

pub fn taos_fetch_raw_block_a(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void);
pub fn taos_fetch_raw_block_a(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void);

pub fn taos_get_raw_block(taos: *mut TAOS_RES) -> *mut c_void;
pub fn taos_get_raw_block(taos: *mut TaosRes) -> *mut c_void;
}

#[c_cfg(taos_result_block)]
extern "C" {
pub fn taos_result_block(res: *mut TAOS_RES) -> *mut TAOS_ROW;
pub fn taos_result_block(res: *mut TaosRes) -> *mut TaosRow;
}

#[cfg(taos_fetch_block_s)]
extern "C" {
pub fn taos_fetch_block_s(
res: *mut TAOS_RES,
res: *mut TaosRes,
num_of_rows: *mut c_int,
rows: *mut TAOS_ROW,
rows: *mut TaosRow,
) -> c_int;
}

#[cfg(not(taos_fetch_block_s))]
#[no_mangle]
pub unsafe extern "C" fn taos_fetch_block_s(
res: *mut TAOS_RES,
res: *mut TaosRes,
num_of_rows: *mut c_int,
rows: *mut TAOS_ROW,
rows: *mut TaosRow,
) -> c_int {
*num_of_rows = taos_fetch_block(res, rows);
return 0;
Expand All @@ -201,25 +201,25 @@ extern "C" {
restart: c_int,
topic: *const c_char,
sql: *const c_char,
fp: Option<taos_subscribe_cb>,
fp: Option<TaosSubscribeCb>,
param: *mut c_void,
interval: c_int,
) -> *mut TAOS_SUB;
) -> *mut TaosSub;

pub fn taos_consume(tsub: *mut TAOS_SUB) -> *mut TAOS_RES;
pub fn taos_consume(tsub: *mut TaosSub) -> *mut TaosRes;

pub fn taos_unsubscribe(tsub: *mut TAOS_SUB, keep_progress: c_int);
pub fn taos_unsubscribe(tsub: *mut TaosSub, keep_progress: c_int);
}

extern "C" {
pub fn taos_open_stream(
taos: *mut TAOS,
sql: *const c_char,
fp: Option<taos_stream_cb>,
fp: Option<TaosStreamCb>,
stime: i64,
param: *mut c_void,
callback: Option<taos_stream_close_cb>,
) -> *mut TAOS_STREAM;
callback: Option<TaosStreamCloseCb>,
) -> *mut TaosStream;

pub fn taos_close_stream(stream: *mut TAOS_STREAM);
pub fn taos_close_stream(stream: *mut TaosStream);
}
14 changes: 7 additions & 7 deletions taos-optin/src/into_c_str.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::ffi::{c_void, CStr, CString};
use std::os::raw::c_char;
// use std::os::raw::c_char;

/// Helper trait to auto convert Rust strings to CStr.
pub trait IntoCStr<'a> {
Expand Down Expand Up @@ -62,12 +62,12 @@ _impl_for_str!(&str);
pub struct NullableCStr<'a>(Option<Cow<'a, CStr>>);

impl<'a> NullableCStr<'a> {
pub fn as_ptr(&self) -> *const c_char {
match self.0.as_ref() {
Some(c) => c.as_ptr(),
None => std::ptr::null(),
}
}
// pub fn as_ptr(&self) -> *const c_char {
// match self.0.as_ref() {
// Some(c) => c.as_ptr(),
// None => std::ptr::null(),
// }
// }
}

pub trait IntoNullableCStr<'a> {
Expand Down
78 changes: 39 additions & 39 deletions taos-optin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,37 @@ mod version {
}

impl Version {
pub(crate) const fn new(mainline: u8, major: u8, minor: u8, patch: u8) -> Self {
Self {
mainline,
major,
minor,
patch,
}
}
fn parse(version: &str) -> Result<Self, Box<dyn std::error::Error>> {
let version_items: Vec<_> = version.split('.').collect();
let items = version_items.len();
if items == 0 || items > 4 {
Err("parse version error: {version}")?
}

let mainline = version_items[0].parse()?;
let major = version_items
.get(1)
.and_then(|s| s.parse().ok())
.unwrap_or_default();
let minor = version_items
.get(2)
.and_then(|s| s.parse().ok())
.unwrap_or_default();
let patch = version_items
.get(3)
.and_then(|s| s.parse().ok())
.unwrap_or_default();

Ok(Self::new(mainline, major, minor, patch))
}
// pub(crate) const fn new(mainline: u8, major: u8, minor: u8, patch: u8) -> Self {
// Self {
// mainline,
// major,
// minor,
// patch,
// }
// }
// fn parse(version: &str) -> Result<Self, Box<dyn std::error::Error>> {
// let version_items: Vec<_> = version.split('.').collect();
// let items = version_items.len();
// if items == 0 || items > 4 {
// Err("parse version error: {version}")?
// }

// let mainline = version_items[0].parse()?;
// let major = version_items
// .get(1)
// .and_then(|s| s.parse().ok())
// .unwrap_or_default();
// let minor = version_items
// .get(2)
// .and_then(|s| s.parse().ok())
// .unwrap_or_default();
// let patch = version_items
// .get(3)
// .and_then(|s| s.parse().ok())
// .unwrap_or_default();

// Ok(Self::new(mainline, major, minor, patch))
// }
}
}
mod into_c_str;
Expand Down Expand Up @@ -216,7 +216,7 @@ impl taos_query::AsyncQueryable for Taos {
/// ```
#[derive(Debug, Default)]
pub struct TaosBuilder {
dsn: Dsn,
_dsn: Dsn,
auth: Auth,
lib: Arc<ApiEntry>,
}
Expand Down Expand Up @@ -328,7 +328,7 @@ impl TBuilder for TaosBuilder {
lib.options(types::TSDB_OPTION::ShellActivityTimer, "3600");

Ok(Self {
dsn,
_dsn: dsn,
auth,
lib: Arc::new(lib),
})
Expand Down Expand Up @@ -381,13 +381,13 @@ impl ResultSet {
self.fields.get_or_init(|| self.raw.fetch_fields())
}

fn ncols(&self) -> usize {
self.raw.field_count()
}
// fn ncols(&self) -> usize {
// self.raw.field_count()
// }

fn names(&self) -> impl Iterator<Item = &str> {
self.fields().iter().map(|f| f.name())
}
// fn names(&self) -> impl Iterator<Item = &str> {
// self.fields().iter().map(|f| f.name())
// }

fn update_summary(&mut self, nrows: usize) {
let summary = self.summary.get_mut();
Expand Down
4 changes: 2 additions & 2 deletions taos-optin/src/query/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::Stream;
use taos_error::Error;
use taos_query::common::{Field, Precision, RawBlock};

use crate::ffi::{taos_get_raw_block, TAOS_RES};
use crate::ffi::{taos_get_raw_block, TaosRes};

use super::raw_res::RawRes;

Expand Down Expand Up @@ -90,7 +90,7 @@ impl Stream for Blocks {
let param = Box::new((&self.shared_state, cx.waker().clone()));
unsafe extern "C" fn async_fetch_callback(
param: *mut c_void,
res: *mut TAOS_RES,
res: *mut TaosRes,
num_of_rows: c_int,
) {
let param = param as *mut (&UnsafeCell<SharedState>, Waker);
Expand Down
Loading

0 comments on commit cf812f8

Please sign in to comment.