diff --git a/Cargo.toml b/Cargo.toml index beaee7a49..cb595851e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libxml" version = "0.3.6" -edition = "2021" +edition = "2024" authors = ["Andreas Franzén ", "Deyan Ginev ","Jan Frederik Schaefer "] description = "A Rust wrapper for libxml2 - the XML C parser and toolkit developed for the Gnome project" repository = "https://github.com/KWARC/rust-libxml" @@ -33,10 +33,9 @@ pkg-config = "0.3.2" pkg-config = "0.3.2" [build-dependencies.bindgen] -version = "0.71" +version = "0.72" features = [ "runtime", - "which-rustfmt", ] default-features = false diff --git a/src/error.rs b/src/error.rs index eae493abe..35501ac91 100644 --- a/src/error.rs +++ b/src/error.rs @@ -66,7 +66,7 @@ impl StructuredError { /// This function copies data from the memory `error_ptr` but does not deallocate /// the error. Depending on the context in which this function is used, you may /// need to take additional steps to avoid a memory leak. - pub unsafe fn from_raw(error_ptr: *const bindings::xmlError) -> Self { + pub unsafe fn from_raw(error_ptr: *const bindings::xmlError) -> Self { unsafe { let error = *error_ptr; let message = StructuredError::ptr_to_string(error.message); let level = XmlErrorLevel::from_raw(error.level); @@ -92,7 +92,7 @@ impl StructuredError { domain: error.domain, code: error.code, } - } + }} /// Human-readable informative error message. /// diff --git a/src/parser.rs b/src/parser.rs index ed9be5cf1..7dafd88f6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -170,7 +170,7 @@ fn xml_open(filename: &str) -> io::Result<*mut c_void> { } /// Read callback for an FS file. -unsafe extern "C" fn xml_read(context: *mut c_void, buffer: *mut c_char, len: c_int) -> c_int { +unsafe extern "C" fn xml_read(context: *mut c_void, buffer: *mut c_char, len: c_int) -> c_int { unsafe { // Len is always positive, typically 40-4000 bytes. let file = context as *mut fs::File; let buf = slice::from_raw_parts_mut(buffer as *mut u8, len as usize); @@ -178,17 +178,17 @@ unsafe extern "C" fn xml_read(context: *mut c_void, buffer: *mut c_char, len: c_ Ok(v) => v as c_int, Err(_) => -1, } -} +}} type XmlReadCallback = unsafe extern "C" fn(*mut c_void, *mut c_char, c_int) -> c_int; /// Close callback for an FS file. -unsafe extern "C" fn xml_close(context: *mut c_void) -> c_int { +unsafe extern "C" fn xml_close(context: *mut c_void) -> c_int { unsafe { // Take rust ownership of the context and then drop it. let file = context as *mut fs::File; let _ = Box::from_raw(file); 0 -} +}} type XmlCloseCallback = unsafe extern "C" fn(*mut c_void) -> c_int; diff --git a/src/tree/document/c14n.rs b/src/tree/document/c14n.rs index 305825117..e82fc7837 100644 --- a/src/tree/document/c14n.rs +++ b/src/tree/document/c14n.rs @@ -55,7 +55,7 @@ impl Document { } } -unsafe fn c_obuf_into_output(c_obuf: xmlOutputBufferPtr) -> String { +unsafe fn c_obuf_into_output(c_obuf: xmlOutputBufferPtr) -> String { unsafe { let ctx_ptr = (*c_obuf).context; let output = Box::from_raw(ctx_ptr as *mut String); @@ -64,9 +64,9 @@ unsafe fn c_obuf_into_output(c_obuf: xmlOutputBufferPtr) -> String { xmlOutputBufferClose(c_obuf); *output -} +}} -unsafe fn create_output_buffer() -> xmlOutputBufferPtr { +unsafe fn create_output_buffer() -> xmlOutputBufferPtr { unsafe { let output = String::new(); let ctx_ptr = Box::into_raw(Box::new(output)); let encoder = std::ptr::null_mut(); @@ -78,7 +78,7 @@ unsafe fn create_output_buffer() -> xmlOutputBufferPtr { (*buf).context = ctx_ptr as _; buf -} +}} unsafe extern "C" fn xml_close_io(_context: *mut raw::c_void) -> raw::c_int { 0 @@ -88,7 +88,7 @@ unsafe extern "C" fn xml_write_io( io_ptr: *mut raw::c_void, buffer: *const raw::c_char, len: raw::c_int, -) -> raw::c_int { +) -> raw::c_int { unsafe { if io_ptr.is_null() { 0 } else { @@ -99,7 +99,7 @@ unsafe extern "C" fn xml_write_io( len } -} +}} /// Create a [Vec] of null-terminated [*mut xmlChar] strings fn to_xml_string_vec(vec: Vec) -> Vec<*mut xmlChar> { diff --git a/src/tree/node.rs b/src/tree/node.rs index bd8335a2a..0bda53018 100644 --- a/src/tree/node.rs +++ b/src/tree/node.rs @@ -221,11 +221,11 @@ impl Node { Some(child) => { let mut current_node = child; while !current_node.is_element_node() { - if let Some(sibling) = current_node.get_next_sibling() { + match current_node.get_next_sibling() { Some(sibling) => { current_node = sibling; - } else { + } _ => { break; - } + }} } if current_node.is_element_node() { Some(current_node) @@ -243,11 +243,11 @@ impl Node { Some(child) => { let mut current_node = child; while !current_node.is_element_node() { - if let Some(sibling) = current_node.get_prev_sibling() { + match current_node.get_prev_sibling() { Some(sibling) => { current_node = sibling; - } else { + } _ => { break; - } + }} } if current_node.is_element_node() { Some(current_node) @@ -265,11 +265,11 @@ impl Node { Some(child) => { let mut current_node = child; while !current_node.is_element_node() { - if let Some(sibling) = current_node.get_next_sibling() { + match current_node.get_next_sibling() { Some(sibling) => { current_node = sibling; - } else { + } _ => { break; - } + }} } if current_node.is_element_node() { Some(current_node) @@ -287,11 +287,11 @@ impl Node { Some(child) => { let mut current_node = child; while !current_node.is_element_node() { - if let Some(sibling) = current_node.get_prev_sibling() { + match current_node.get_prev_sibling() { Some(sibling) => { current_node = sibling; - } else { + } _ => { break; - } + }} } if current_node.is_element_node() { Some(current_node) @@ -1085,7 +1085,7 @@ impl Node { // nothing to do here, already in place Ok(old) } else if self.get_type() == Some(NodeType::ElementNode) { - if let Some(old_parent) = old.get_parent() { + match old.get_parent() { Some(old_parent) => { if &old_parent == self { // unlink new to be available for insertion new.unlink(); @@ -1100,12 +1100,12 @@ impl Node { old_parent.get_name() ))) } - } else { + } _ => { Err(From::from(format!( "Old node was not a child of {:?} parent. No registered parent exists.", self.get_name() ))) - } + }} } else { Err(From::from( "Can only call replace_child_node an a NodeType::Element type parent.", diff --git a/tests/tree_tests.rs b/tests/tree_tests.rs index 59ec8c0bc..b03604072 100644 --- a/tests/tree_tests.rs +++ b/tests/tree_tests.rs @@ -15,17 +15,17 @@ fn child_of_root_has_different_hash() { let doc = doc_result.unwrap(); let root = doc.get_root_element().unwrap(); assert!(!root.is_text_node()); - if let Some(child) = root.get_first_child() { + match root.get_first_child() { Some(child) => { assert!(root != child); - } else { + } _ => { assert!(false); //test failed - child doesn't exist - } + }} // same check with last child - if let Some(child) = root.get_last_child() { + match root.get_last_child() { Some(child) => { assert!(root != child); - } else { + } _ => { assert!(false); //test failed - child doesn't exist - } + }} } } diff --git a/tests/xpath_tests.rs b/tests/xpath_tests.rs index 8f09cfa55..bcfcaaac8 100644 --- a/tests/xpath_tests.rs +++ b/tests/xpath_tests.rs @@ -200,7 +200,7 @@ fn xpath_find_string_values() { assert!(doc_result.is_ok()); let doc = doc_result.unwrap(); let mut xpath = libxml::xpath::Context::new(&doc).unwrap(); - if let Some(root) = doc.get_root_element() { + match doc.get_root_element() { Some(root) => { let tests = root.get_child_elements(); let empty_test = &tests[0]; let ids_test = &tests[1]; @@ -211,9 +211,9 @@ fn xpath_find_string_values() { assert_eq!(ids_values, expected_ids); let node_ids_values = ids_test.findvalues(".//@xml:id"); assert_eq!(node_ids_values, expected_ids); - } else { + } _ => { panic!("Document fails to obtain root!"); - } + }} } /// Tests for checking xpath well-formedness