Merge pull request #25 from TheBlueMatt/2021-04-bp-inclusion
[ldk-c-bindings] / lightning-c-bindings / src / lightning / util / logger.rs
index b38fac0ffb76b1d3ec4a50fd3095338ffcccdd57..6a21fcbefcaa84d322fc5d8c2f7171ab4b3916cb 100644 (file)
@@ -88,6 +88,21 @@ impl Level {
 pub extern "C" fn Level_clone(orig: &Level) -> Level {
        orig.clone()
 }
+/// Checks if two Levels contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn Level_eq(a: &Level, b: &Level) -> bool {
+       if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// Checks if two Levels contain equal inner contents.
+#[no_mangle]
+pub extern "C" fn Level_hash(o: &Level) -> u64 {
+       // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
+       #[allow(deprecated)]
+       let mut hasher = core::hash::SipHasher::new();
+       std::hash::Hash::hash(&o.to_native(), &mut hasher);
+       std::hash::Hasher::finish(&hasher)
+}
 /// Returns the most verbose logging level.
 #[must_use]
 #[no_mangle]
@@ -108,12 +123,12 @@ pub struct Logger {
        /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
        pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
 }
-unsafe impl Sync for Logger {}
 unsafe impl Send for Logger {}
+unsafe impl Sync for Logger {}
 
 use lightning::util::logger::Logger as rustLogger;
 impl rustLogger for Logger {
-       fn log(&self, record: &lightning::util::logger::Record) {
+       fn log(&self, mut record: &lightning::util::logger::Record) {
                let mut local_record = std::ffi::CString::new(format!("{}", record.args)).unwrap();
                (self.log)(self.this_arg, local_record.as_ptr())
        }