Skip to content

Commit

Permalink
fix(fmt): Fixed fmt warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
breadrock1 committed Jul 11, 2024
1 parent 6610355 commit 8413b5b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 41 deletions.
6 changes: 1 addition & 5 deletions adblock-rs/src/adblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ mod adblock_test {

let advt_blocker = AdvtBlocker::new(rules);
let check_result = advt_blocker
.check_network_urls(
"hvertisement-icon.",
"http://exampworld",
"kek",
)
.check_network_urls("hvertisement-icon.", "http://exampworld", "kek")
.unwrap_or_else(|err| {
log::error!("{:?}", err.to_string());
false
Expand Down
2 changes: 1 addition & 1 deletion adblock-rs/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl From<RequestError> for RustException {
}
}

impl <T> From<PoisonError<T>> for RustException {
impl<T> From<PoisonError<T>> for RustException {
fn from(value: PoisonError<T>) -> Self {
RustException::MutexGuardLock(value.to_string())
}
Expand Down
29 changes: 13 additions & 16 deletions adblock-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod adblock;
mod errors;
mod wrapper;
mod logger;
mod wrapper;

use jni::objects::{JObject, JObjectArray, JString};
use jni::sys::{jboolean, jlong};
Expand All @@ -15,11 +15,10 @@ pub extern "system" fn Java_com_example_adblock_AdvtBlocker_initObject(
_class: JObject,
rules: JObjectArray,
) -> jlong {
init_object_wrapped(&mut env, &rules)
.unwrap_or_else(|err| {
log::error!("{:?}", err);
-1_i64 as jlong
})
init_object_wrapped(&mut env, &rules).unwrap_or_else(|err| {
log::error!("{:?}", err);
-1_i64 as jlong
})
}

#[no_mangle]
Expand All @@ -28,11 +27,10 @@ pub extern "system" fn Java_com_example_adblock_AdvtBlocker_destroyObject(
_class: JObject,
ptr: jlong,
) -> jboolean {
destroy_object_wrapped(&mut env, ptr)
.unwrap_or_else(|err| {
log::error!("{:?}", err);
false as jboolean
})
destroy_object_wrapped(&mut env, ptr).unwrap_or_else(|err| {
log::error!("{:?}", err);
false as jboolean
})
}

#[no_mangle]
Expand All @@ -44,9 +42,8 @@ pub extern "system" fn Java_com_example_adblock_AdvtBlocker_checkNetworkUrls(
src_url: JString,
req_type: JString,
) -> jboolean {
check_net_urls_wrapped(&mut env, ptr, &url, &src_url, &req_type)
.unwrap_or_else(|err| {
log::error!("{:?}", err);
false as jboolean
})
check_net_urls_wrapped(&mut env, ptr, &url, &src_url, &req_type).unwrap_or_else(|err| {
log::error!("{:?}", err);
false as jboolean
})
}
3 changes: 2 additions & 1 deletion adblock-rs/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ lazy_static! {
android_logger::init_once(
Config::default()
.with_tag("Tag_RustAdvtBlocker")
.with_max_level(LevelFilter::max()));
.with_max_level(LevelFilter::max()),
);
});

#[cfg(not(target_os = "android"))]
Expand Down
24 changes: 6 additions & 18 deletions adblock-rs/src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ pub(crate) fn init_object_wrapped(
rules: &JObjectArray,
) -> Result<jlong, RustException> {
let conv_rules = extract_list_str(env, rules)?;
let mut instance_lock = INSTANCE
.lock()
.map_err(RustException::from)?;
let mut instance_lock = INSTANCE.lock().map_err(RustException::from)?;

instance_lock.recreate(conv_rules);

Expand All @@ -34,9 +32,7 @@ pub(crate) fn destroy_object_wrapped(
_env: &mut JNIEnv,
_ptr: jlong,
) -> Result<jboolean, RustException> {
let instance_lock = INSTANCE
.lock()
.map_err(RustException::from)?;
let instance_lock = INSTANCE.lock().map_err(RustException::from)?;

drop(instance_lock);
Ok(true as jboolean)
Expand All @@ -49,9 +45,7 @@ pub(crate) fn check_net_urls_wrapped(
src_url: &JString,
req_type: &JString,
) -> Result<jboolean, RustException> {
let advt_blocker = INSTANCE
.lock()
.map_err(RustException::from)?;
let advt_blocker = INSTANCE.lock().map_err(RustException::from)?;

let url_str = extract_str(env, url)?;
let src_url_str = extract_str(env, src_url)?;
Expand All @@ -67,9 +61,7 @@ pub(crate) fn check_net_urls_wrapped(
}

fn extract_str<'a>(env: &'a mut JNIEnv, j_obj: &'a JString) -> Result<String, RustException> {
let j_str = env
.get_string(&j_obj)
.map_err(RustException::from)?;
let j_str = env.get_string(&j_obj).map_err(RustException::from)?;

let str_obj = j_str
.to_str()
Expand All @@ -82,13 +74,9 @@ fn extract_list_str<'a>(
env: &'a mut JNIEnv,
j_obj_arr: &'a JObjectArray,
) -> Result<Vec<String>, RustException> {
let j_list = env
.get_list(&j_obj_arr)
.map_err(RustException::from)?;
let j_list = env.get_list(&j_obj_arr).map_err(RustException::from)?;

let j_list_size = j_list
.size(env)
.map_err(RustException::from)?;
let j_list_size = j_list.size(env).map_err(RustException::from)?;

let mut list_data = Vec::with_capacity(j_list_size as usize);
for index in 0..j_list_size {
Expand Down

0 comments on commit 8413b5b

Please sign in to comment.