Skip to content

Commit ef9a83d

Browse files
committed
Fix cargo fmt and cargo clippy pass
1 parent 0252ab6 commit ef9a83d

7 files changed

Lines changed: 73 additions & 67 deletions

File tree

build.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ fn main() {
2323
"https://github.com/webui-dev/webui/releases/download/nightly/{}.zip",
2424
zip_name
2525
);
26-
println!("cargo:warning=WebUI library not found. Downloading: {}", url);
26+
println!(
27+
"cargo:warning=WebUI library not found. Downloading: {}",
28+
url
29+
);
2730
fetch_library(&url, &zip_name, lib_filename, &manifest_dir);
2831
println!("cargo:warning=WebUI library ready.");
2932
}
@@ -78,12 +81,7 @@ fn fetch_library(url: &str, zip_name: &str, lib_filename: &str, dest_dir: &str)
7881
),
7982
]));
8083
} else {
81-
run(Command::new("curl").args([
82-
"-fsSL",
83-
"-o",
84-
zip_path.to_str().unwrap(),
85-
url,
86-
]));
84+
run(Command::new("curl").args(["-fsSL", "-o", zip_path.to_str().unwrap(), url]));
8785
}
8886

8987
// Extract
@@ -99,13 +97,7 @@ fn fetch_library(url: &str, zip_name: &str, lib_filename: &str, dest_dir: &str)
9997
),
10098
]));
10199
} else {
102-
run(Command::new("unzip").args([
103-
"-q",
104-
"-o",
105-
zip_path.to_str().unwrap(),
106-
"-d",
107-
dest_dir,
108-
]));
100+
run(Command::new("unzip").args(["-q", "-o", zip_path.to_str().unwrap(), "-d", dest_dir]));
109101
}
110102

111103
// Copy static lib to project root

examples/call_js_from_rust/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn my_function_count(e: webui::Event) {
9797

9898
// Run JS without capturing return value (faster)
9999
// No buffer needed since this is a fire and forget call.
100-
window.run(&format!("SetCount({next});"));
100+
window.run(format!("SetCount({next});"));
101101
}
102102

103103
fn main() {

examples/call_rust_from_js/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ const HTML: &str = r#"<!DOCTYPE html>
6868

6969
fn my_function_string(e: webui::Event) {
7070
// JavaScript: my_function_string('Hello', 'World')
71-
println!("my_function_string 1: {}", e.get_string()); // Hello
71+
println!("my_function_string 1: {}", e.get_string()); // Hello
7272
println!("my_function_string 2: {}", e.get_string_at(1)); // World
7373
}
7474

7575
fn my_function_integer(e: webui::Event) {
7676
// JavaScript: my_function_integer(123, 456, 789, 12345.6789)
7777
println!("my_function_integer: {} arguments", e.get_count());
78-
println!("my_function_integer 1: {}", e.get_int()); // 123
79-
println!("my_function_integer 2: {}", e.get_int_at(1)); // 456
80-
println!("my_function_integer 3: {}", e.get_int_at(2)); // 789
81-
println!("my_function_integer 4: {}", e.get_float_at(3)); // 12345.6789
78+
println!("my_function_integer 1: {}", e.get_int()); // 123
79+
println!("my_function_integer 2: {}", e.get_int_at(1)); // 456
80+
println!("my_function_integer 3: {}", e.get_int_at(2)); // 789
81+
println!("my_function_integer 4: {}", e.get_float_at(3)); // 12345.6789
8282
}
8383

8484
fn my_function_boolean(e: webui::Event) {
8585
// JavaScript: my_function_boolean(true, false)
86-
println!("my_function_boolean 1: {}", e.get_bool()); // true
87-
println!("my_function_boolean 2: {}", e.get_bool_at(1)); // false
86+
println!("my_function_boolean 1: {}", e.get_bool()); // true
87+
println!("my_function_boolean 2: {}", e.get_bool_at(1)); // false
8888
}
8989

9090
fn my_function_raw_binary(e: webui::Event) {
@@ -99,7 +99,10 @@ fn my_function_raw_binary(e: webui::Event) {
9999
println!();
100100

101101
let valid = bytes2.first() == Some(&0xA1) && bytes2.last() == Some(&0xA2);
102-
println!("my_function_raw_binary 2 big ({} bytes): valid? {valid}", bytes2.len());
102+
println!(
103+
"my_function_raw_binary 2 big ({} bytes): valid? {valid}",
104+
bytes2.len()
105+
);
103106
}
104107

105108
fn my_function_with_response(e: webui::Event) {

examples/minimal/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use webui_rs::webui;
44

55
fn main() {
66
let window = webui::Window::new();
7-
window.show("<html><head><script src=\"webui.js\"></script></head><body>Hello World!</body></html>");
7+
window.show(
8+
"<html><head><script src=\"webui.js\"></script></head><body>Hello World!</body></html>",
9+
);
810
webui::wait();
911
}

examples/public_network_access/main.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ fn public_window_events(e: webui::Event) {
7878
let private = PRIVATE_WIN.load(Ordering::SeqCst);
7979
match e.event_type {
8080
webui::EventType::Connected => {
81-
webui::run(private, "document.getElementById('Logs').value += 'New connection.\\n';");
81+
webui::run(
82+
private,
83+
"document.getElementById('Logs').value += 'New connection.\\n';",
84+
);
8285
}
8386
webui::EventType::Disconnected => {
84-
webui::run(private, "document.getElementById('Logs').value += 'Disconnected.\\n';");
87+
webui::run(
88+
private,
89+
"document.getElementById('Logs').value += 'Disconnected.\\n';",
90+
);
8591
}
8692
_ => {}
8793
}
@@ -95,20 +101,21 @@ fn private_window_events(e: webui::Event) {
95101
let port = webui::get_port(public);
96102
let url = webui::get_url(public);
97103

98-
webui::run(private, format!(
99-
"document.getElementById('urlSpan1').innerHTML = 'http://localhost:{port}';"
100-
));
101-
webui::run(private, format!(
102-
"document.getElementById('urlSpan2').innerHTML = '{url}';"
103-
));
104+
webui::run(
105+
private,
106+
format!("document.getElementById('urlSpan1').innerHTML = 'http://localhost:{port}';"),
107+
);
108+
webui::run(
109+
private,
110+
format!("document.getElementById('urlSpan2').innerHTML = '{url}';"),
111+
);
104112
webui::run(private, format!(
105113
"document.getElementById('urlSpan3').innerHTML = 'http://[ANY_IP_OF_THIS_MACHINE]:{port}';"
106114
));
107115
}
108116
}
109117

110118
fn main() {
111-
112119
// Allow multiple connections to the same window
113120
webui::set_config(webui::Config::MultiClient, true);
114121

src/webui.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,15 @@ impl Window {
376376
data: "".to_string(),
377377
};
378378

379-
run_js_buffered(self.id, &mut js, if buffer_size == 0 { 1024 * 8 } else { buffer_size });
379+
run_js_buffered(
380+
self.id,
381+
&mut js,
382+
if buffer_size == 0 {
383+
1024 * 8
384+
} else {
385+
buffer_size
386+
},
387+
);
380388

381389
js
382390
}
@@ -447,10 +455,7 @@ impl Window {
447455
set_root_folder(self.id, path.as_ref())
448456
}
449457

450-
pub fn set_close_handler_wv(
451-
&self,
452-
handler: unsafe extern "C" fn(usize) -> bool,
453-
) {
458+
pub fn set_close_handler_wv(&self, handler: unsafe extern "C" fn(usize) -> bool) {
454459
set_close_handler_wv(self.id, handler);
455460
}
456461

@@ -795,7 +800,7 @@ pub fn start_server(win: usize, content: impl AsRef<str> + Into<Vec<u8>>) -> Str
795800
let content_c_str = CString::new(content).unwrap();
796801
let content_c_char: *const c_char = content_c_str.as_ptr() as *const c_char;
797802
let url = webui_start_server(win, content_c_char);
798-
char_to_string(url as *const i8)
803+
char_to_string(url)
799804
}
800805
}
801806

@@ -882,7 +887,7 @@ pub fn open_url(url: impl AsRef<str> + Into<Vec<u8>>) {
882887
pub fn get_url(win: usize) -> String {
883888
unsafe {
884889
let url = webui_get_url(win);
885-
char_to_string(url as *const i8)
890+
char_to_string(url)
886891
}
887892
}
888893

@@ -939,11 +944,18 @@ pub fn set_transparent(win: usize, status: bool) {
939944
pub fn get_mime_type(file: impl AsRef<str> + Into<Vec<u8>>) -> String {
940945
let file_c_str = CString::new(file).unwrap();
941946
let file_c_char: *const c_char = file_c_str.as_ptr() as *const c_char;
942-
unsafe { char_to_string(webui_get_mime_type(file_c_char) as *const i8) }
947+
unsafe { char_to_string(webui_get_mime_type(file_c_char)) }
943948
}
944949

945-
pub fn memcpy(dest: *mut std::os::raw::c_void, src: *mut std::os::raw::c_void, count: usize) {
946-
unsafe { webui_memcpy(dest, src, count) }
950+
/// # Safety
951+
///
952+
/// `dest` and `src` must be valid non-overlapping pointers to at least `count` bytes.
953+
pub unsafe fn memcpy(
954+
dest: *mut std::os::raw::c_void,
955+
src: *mut std::os::raw::c_void,
956+
count: usize,
957+
) {
958+
webui_memcpy(dest, src, count)
947959
}
948960

949961
pub fn send_raw(win: usize, func: impl AsRef<str> + Into<Vec<u8>>, raw: &[u8]) {
@@ -996,7 +1008,7 @@ pub fn get_last_error_number() -> usize {
9961008
}
9971009

9981010
pub fn get_last_error_message() -> String {
999-
unsafe { char_to_string(webui_get_last_error_message() as *const i8) }
1011+
unsafe { char_to_string(webui_get_last_error_message()) }
10001012
}
10011013

10021014
pub fn set_default_root_folder(path: impl AsRef<str> + Into<Vec<u8>>) -> bool {
@@ -1033,10 +1045,11 @@ pub fn delete_profile(win: usize) {
10331045

10341046
/// Allocate a response buffer owned by WebUI so it frees the memory after serving.
10351047
/// Use this inside a `set_file_handler` callback to return dynamic content.
1036-
pub unsafe fn malloc(
1037-
response: &str,
1038-
length: *mut i32,
1039-
) -> *const std::os::raw::c_void {
1048+
///
1049+
/// # Safety
1050+
///
1051+
/// `length` must be either null or a valid pointer to a writable `i32`.
1052+
pub unsafe fn malloc(response: &str, length: *mut i32) -> *const std::os::raw::c_void {
10401053
let buf = webui_malloc(response.len() + 1) as *mut u8;
10411054
std::ptr::copy_nonoverlapping(response.as_ptr(), buf, response.len());
10421055
*buf.add(response.len()) = 0;

src/webui/bindgen.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ extern "C" {
5454
}
5555
extern "C" {
5656
#[doc = " @brief Show a window using embedded HTML, or a file. Single client.\n\n @param e The event struct\n @param content The HTML, URL, Or a local file\n\n @return Returns True if showing the window is successed.\n\n @example webui_show_client(e, \"<html>...</html>\");"]
57-
pub fn webui_show_client(
58-
e: *mut webui_event_t,
59-
content: *const ::std::os::raw::c_char,
60-
) -> bool;
57+
pub fn webui_show_client(e: *mut webui_event_t, content: *const ::std::os::raw::c_char)
58+
-> bool;
6159
}
6260
extern "C" {
6361
#[doc = " @brief Same as `webui_show()`. But using a specific web browser.\n\n @param window The window number\n @param content The HTML, Or a local file\n @param browser The web browser to be used\n\n @return Returns True if showing the window is successed.\n\n @example webui_show_browser(myWindow, \"<html>...</html>\", Chrome); |\n webui_show(myWindow, \"index.html\", Firefox);"]
@@ -76,10 +74,7 @@ extern "C" {
7674
}
7775
extern "C" {
7876
#[doc = " @brief Show a WebView window using embedded HTML, or a file.\n\n @param window The window number\n @param content The HTML, URL, Or a local file\n\n @return Returns True if showing the WebView window is successed.\n\n @example webui_show_wv(myWindow, \"<html>...</html>\");"]
79-
pub fn webui_show_wv(
80-
window: usize,
81-
content: *const ::std::os::raw::c_char,
82-
) -> bool;
77+
pub fn webui_show_wv(window: usize, content: *const ::std::os::raw::c_char) -> bool;
8378
}
8479
extern "C" {
8580
#[doc = " @brief Set the window in Kiosk mode (Full screen).\n\n @param window The window number\n @param status True or False\n\n @example webui_set_kiosk(myWindow, true);"]
@@ -91,10 +86,7 @@ extern "C" {
9186
}
9287
extern "C" {
9388
#[doc = " @brief Add a user-defined web browser's CLI parameters.\n\n @param window The window number\n @param params Command line parameters\n\n @example webui_set_custom_parameters(myWindow, \"--remote-debugging-port=9222\");"]
94-
pub fn webui_set_custom_parameters(
95-
window: usize,
96-
params: *mut ::std::os::raw::c_char,
97-
);
89+
pub fn webui_set_custom_parameters(window: usize, params: *mut ::std::os::raw::c_char);
9890
}
9991
extern "C" {
10092
#[doc = " @brief Set the window with high-contrast support.\n\n @param window The window number\n @param status True or False\n\n @example webui_set_high_contrast(myWindow, true);"]
@@ -385,8 +377,9 @@ extern "C" {
385377
}
386378
extern "C" {
387379
#[doc = " @brief Get the HTTP mime type of a file.\n\n @return Returns the HTTP mime string\n\n @example const char* mime = webui_get_mime_type(\"foo.png\");"]
388-
pub fn webui_get_mime_type(file: *const ::std::os::raw::c_char)
389-
-> *const ::std::os::raw::c_char;
380+
pub fn webui_get_mime_type(
381+
file: *const ::std::os::raw::c_char,
382+
) -> *const ::std::os::raw::c_char;
390383
}
391384
extern "C" {
392385
#[doc = " @brief Set the SSL/TLS certificate and the private key content, both in PEM\n format. This works only with `webui-2-secure` library. If set empty WebUI\n will generate a self-signed certificate.\n\n @param certificate_pem The SSL/TLS certificate content in PEM format\n @param private_key_pem The private key content in PEM format\n\n @return Returns True if the certificate and the key are valid.\n\n @example bool ret = webui_set_tls_certificate(\"-----BEGIN\n CERTIFICATE-----\\n...\", \"-----BEGIN PRIVATE KEY-----\\n...\");"]
@@ -556,11 +549,7 @@ extern "C" {
556549
}
557550
extern "C" {
558551
#[doc = " @brief Get an argument as float at a specific index.\n\n @param window The window number\n @param event_number The event number\n @param index The argument position\n\n @return Returns argument as float\n\n @example double myFloat = webui_interface_get_float_at(myWindow, e->event_number, 0);"]
559-
pub fn webui_interface_get_float_at(
560-
window: usize,
561-
event_number: usize,
562-
index: usize,
563-
) -> f64;
552+
pub fn webui_interface_get_float_at(window: usize, event_number: usize, index: usize) -> f64;
564553
}
565554
extern "C" {
566555
#[doc = " @brief Show a window using embedded HTML, or a file. Single client.\n\n @param window The window number\n @param event_number The event number\n @param content The HTML, URL, Or a local file\n\n @return Returns True if showing the window is successed.\n\n @example webui_interface_show_client(myWindow, e->event_number, \"<html>...</html>\");"]

0 commit comments

Comments
 (0)