X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Flogger.rs;h=452da100eac8fa90140a20160be9fe074b3a00ff;hb=3e46e1794f14640e35f09cc6da4169c152de34ce;hp=411a34fd8634fc492a52267caf3bd9cd4587aa74;hpb=b2819774e287d465e23415cbfdaa397e2e0a2749;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/util/logger.rs b/lightning-c-bindings/src/lightning/util/logger.rs index 411a34f..452da10 100644 --- a/lightning-c-bindings/src/lightning/util/logger.rs +++ b/lightning-c-bindings/src/lightning/util/logger.rs @@ -14,6 +14,7 @@ //! Each module may have its own Logger or share one. use alloc::str::FromStr; +use alloc::string::String; use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; @@ -22,8 +23,8 @@ use crate::c_types::*; use alloc::{vec::Vec, boxed::Box}; /// An enum representing the available verbosity levels of the logger. -#[must_use] #[derive(Clone)] +#[must_use] #[repr(C)] pub enum Level { /// Designates extremely verbose information, including gossip-induced messages @@ -39,7 +40,9 @@ pub enum Level { /// Designates very serious errors Error, } -use lightning::util::logger::Level as nativeLevel; +use lightning::util::logger::Level as LevelImport; +pub(crate) type nativeLevel = LevelImport; + impl Level { #[allow(unused)] pub(crate) fn to_native(&self) -> nativeLevel { @@ -121,7 +124,7 @@ pub extern "C" fn Level_error() -> Level { 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. +/// Generates a non-cryptographic 64-bit hash of the Level. #[no_mangle] pub extern "C" fn Level_hash(o: &Level) -> u64 { // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core @@ -172,7 +175,7 @@ pub extern "C" fn Record_free(this_obj: Record) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Record_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRecord); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRecord) }; } #[allow(unused)] impl Record { @@ -278,8 +281,7 @@ pub struct Logger { } unsafe impl Send for Logger {} unsafe impl Sync for Logger {} -#[no_mangle] -pub(crate) extern "C" fn Logger_clone_fields(orig: &Logger) -> Logger { +pub(crate) fn Logger_clone_fields(orig: &Logger) -> Logger { Logger { this_arg: orig.this_arg, log: Clone::clone(&orig.log), @@ -302,6 +304,11 @@ impl core::ops::Deref for Logger { self } } +impl core::ops::DerefMut for Logger { + fn deref_mut(&mut self) -> &mut Self { + self + } +} /// Calls the free function if one is set #[no_mangle] pub extern "C" fn Logger_free(this_ptr: Logger) { }