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 5, 2024
1 parent fa1261f commit da9c676
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
14 changes: 8 additions & 6 deletions adblock-rs/src/adblock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use adblock::{Engine, FilterSet};
use adblock::lists::ParseOptions;
use adblock::request::Request;
use adblock::{Engine, FilterSet};

use crate::errors::RustException;

Expand Down Expand Up @@ -55,11 +55,13 @@ mod adblock_test {
];

let advt_blocker = AdvtBlocker::new(rules);
let check_result = advt_blocker.check_network_urls(
"http://example.com/-advertisement-icon.",
"http://example.com/helloworld",
"image"
).unwrap();
let check_result = advt_blocker
.check_network_urls(
"http://example.com/-advertisement-icon.",
"http://example.com/helloworld",
"image",
)
.unwrap();

assert_eq!(check_result, true);
}
Expand Down
2 changes: 1 addition & 1 deletion adblock-rs/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use jni::errors::{Exception, ToException};

use std::fmt::Debug;
use adblock::request::RequestError;
use std::fmt::Debug;
use thiserror::Error;

#[derive(Debug, Error)]
Expand Down
12 changes: 5 additions & 7 deletions adblock-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ mod adblock;
mod errors;
mod wrapper;

use jni::JNIEnv;
use jni::objects::{JObject, JObjectArray, JString};
use jni::sys::{jboolean, jlong};
use jni::JNIEnv;

use crate::wrapper::*;

Expand Down Expand Up @@ -32,10 +32,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
})
}

20 changes: 11 additions & 9 deletions adblock-rs/src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use jni::JNIEnv;
use jni::objects::{JObjectArray, JString};
use jni::sys::{jboolean, jlong};
use jni::JNIEnv;

use crate::adblock::AdvtBlocker;
use crate::errors::RustException;

pub(crate) fn init_object_wrapped(
env: &mut JNIEnv,
rules: &JObjectArray
rules: &JObjectArray,
) -> Result<AdvtBlocker, RustException> {
let conv_rules = extract_list_str(env, rules)?;
Ok(AdvtBlocker::new(conv_rules))
Expand All @@ -29,12 +29,11 @@ pub(crate) fn check_net_urls_wrapped(

let req_type_str = extract_str(env, req_type)?;

let check_result = advt_blocker
.check_network_urls(
url_str.as_str(),
src_url_str.as_str(),
req_type_str.as_str(),
)?;
let check_result = advt_blocker.check_network_urls(
url_str.as_str(),
src_url_str.as_str(),
req_type_str.as_str(),
)?;

Ok(check_result as jboolean)
}
Expand All @@ -52,7 +51,10 @@ fn extract_str<'a>(env: &'a mut JNIEnv, j_obj: &'a JString) -> Result<String, Ru
Ok(str_obj.to_string())
}

fn extract_list_str<'a>(env: &'a mut JNIEnv, j_obj_arr: &'a JObjectArray) -> Result<Vec<String>, RustException> {
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(|err| RustException::ExtractParameter(err.to_string()))?;
Expand Down

0 comments on commit da9c676

Please sign in to comment.