@ -97,7 +97,7 @@ impl Logger
idx
idx
}
}
/// Try to remove and return a logging hook.
/// Try to remove and return the removed logging hook.
///
///
/// # Returns
/// # Returns
/// `None` if `hook` is not present or its `RwLock` was poisoned, otherwise, returns boxed trait object of the hook.
/// `None` if `hook` is not present or its `RwLock` was poisoned, otherwise, returns boxed trait object of the hook.
@ -114,6 +114,53 @@ impl Logger
. flatten ( )
. flatten ( )
}
}
/// Try to remove, downcast, and return the removed logging hook. Assume the downcasting will not fail.
///
/// # Returns
/// `None` if [remove_hook]`remove_hook` returns `None`, `Some(H)` if it is removed successfully **and also** downcasted successfully.
///
/// Function will also return `None` if removal was successful but downcasting was not.
///
/// If this it not desireable, check [remove_hook_try_downcasted]`remove_hook_try_downcasted`.
pub fn remove_hook_assume_downcasted < H : custom ::Hook , I : Into < Index > > ( & self , hook : I ) -> Option < H >
{
if let Some ( bx ) = self . remove_hook ( hook ) {
bx . downcast ( ) . ok ( ) . map ( | x | * x )
} else {
None
}
}
/// Remove, downcast, and return the removed logging hook.
///
/// # Returns
/// `None` if [remove_hook]`remove_hook` returns `None`, `Some(H)` if it is removed successfully **and also** downcasted successfully.
///
/// # Panics
///
/// If downcasting fails
pub fn remove_hook_downcasted < H : custom ::Hook , I : Into < Index > > ( & self , hook : I ) -> Option < H >
{
if let Some ( bx ) = self . remove_hook ( hook ) {
Some ( * bx . downcast ( ) . expect ( "Downcast failed on removed hook" ) )
} else {
None
}
}
/// Try to remove, downcast, and return the removed logging hook.
///
/// # Returns
/// `Err(false)` if [remove_hook]`remove_hook` returns `None`, `Ok(H)` if it is removed successfully **and also** downcasted successfully. `Err(true)` if removal was successful but not downcasting.
pub fn remove_hook_try_downcasted < H : custom ::Hook , I : Into < Index > > ( & self , hook : I ) -> Result < H , bool >
{
if let Some ( bx ) = self . remove_hook ( hook ) {
bx . downcast ( ) . map_err ( | _ | true ) . map ( | x | * x )
} else {
Err ( false )
}
}
/// Print a line to this logger.
/// Print a line to this logger.
/// You should usually print using the macros defined here instead of calling this directly.
/// You should usually print using the macros defined here instead of calling this directly.
pub fn println < W , L , D , T > ( & self , mut to : W , level : L , what : D , trace : T ) -> io ::Result < ( ) >
pub fn println < W , L , D , T > ( & self , mut to : W , level : L , what : D , trace : T ) -> io ::Result < ( ) >