X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Flogger.rs;h=00cd10e34def3e699cdb6626a9417ce2327d5b40;hb=ae39d0e5a34ef021db50b12a7be96f0694fd1b18;hp=b4d7c1a741946e4238c2bb0891350d307b1e6779;hpb=a945b11d9f16864753054a47128d71a96de29f73;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 b4d7c1a..00cd10e 100644 --- a/lightning-c-bindings/src/lightning/util/logger.rs +++ b/lightning-c-bindings/src/lightning/util/logger.rs @@ -13,17 +13,21 @@ //! The second one, client-side by implementing check against Record Level field. //! Each module may have its own Logger or share one. -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +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 + Gossip, /// Designates very low priority, often extremely verbose, information Trace, /// Designates lower priority information @@ -35,11 +39,14 @@ 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 { match self { + Level::Gossip => nativeLevel::Gossip, Level::Trace => nativeLevel::Trace, Level::Debug => nativeLevel::Debug, Level::Info => nativeLevel::Info, @@ -50,6 +57,7 @@ impl Level { #[allow(unused)] pub(crate) fn into_native(self) -> nativeLevel { match self { + Level::Gossip => nativeLevel::Gossip, Level::Trace => nativeLevel::Trace, Level::Debug => nativeLevel::Debug, Level::Info => nativeLevel::Info, @@ -60,6 +68,7 @@ impl Level { #[allow(unused)] pub(crate) fn from_native(native: &nativeLevel) -> Self { match native { + nativeLevel::Gossip => Level::Gossip, nativeLevel::Trace => Level::Trace, nativeLevel::Debug => Level::Debug, nativeLevel::Info => Level::Info, @@ -70,6 +79,7 @@ impl Level { #[allow(unused)] pub(crate) fn native_into(native: nativeLevel) -> Self { match native { + nativeLevel::Gossip => Level::Gossip, nativeLevel::Trace => Level::Trace, nativeLevel::Debug => Level::Debug, nativeLevel::Info => Level::Info, @@ -84,6 +94,10 @@ pub extern "C" fn Level_clone(orig: &Level) -> Level { orig.clone() } #[no_mangle] +/// Utility method to constructs a new Gossip-variant Level +pub extern "C" fn Level_gossip() -> Level { + Level::Gossip} +#[no_mangle] /// Utility method to constructs a new Trace-variant Level pub extern "C" fn Level_trace() -> Level { Level::Trace} @@ -112,11 +126,11 @@ pub extern "C" fn Level_eq(a: &Level, b: &Level) -> bool { /// 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 + // Note that we'd love to use alloc::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) + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) } /// Returns the most verbose logging level. #[must_use] @@ -174,7 +188,7 @@ impl Record { pub(crate) fn take_inner(mut self) -> *mut nativeRecord { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); - self.inner = std::ptr::null_mut(); + self.inner = core::ptr::null_mut(); ret } } @@ -236,7 +250,7 @@ pub extern "C" fn Record_set_line(this_ptr: &mut Record, mut val: u32) { impl Clone for Record { fn clone(&self) -> Self { Self { - inner: if <*mut nativeRecord>::is_null(self.inner) { std::ptr::null_mut() } else { + inner: if <*mut nativeRecord>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -284,7 +298,7 @@ impl rustLogger for Logger { // We're essentially a pointer already, or at least a set of pointers, so allow us to be used // directly as a Deref trait in higher-level structs: -impl std::ops::Deref for Logger { +impl core::ops::Deref for Logger { type Target = Self; fn deref(&self) -> &Self { self