forked from pola-rs/polars
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust, python):
polars_warn!
macro (pola-rs#9868)
- Loading branch information
Showing
11 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
type WarningFunction = fn(&str); | ||
static mut WARNING_FUNCTION: Option<WarningFunction> = None; | ||
|
||
/// Set the function that will be called by the `polars_warn!` macro. | ||
/// You can use this to set logging in polars. | ||
/// | ||
/// # Safety | ||
/// The caller must ensure there is no other thread accessing this function | ||
/// or calling `polars_warn!`. | ||
pub unsafe fn set_warning_function(function: WarningFunction) { | ||
WARNING_FUNCTION = Some(function) | ||
} | ||
|
||
fn eprintln(fmt: &str) { | ||
eprintln!("{}", fmt); | ||
} | ||
|
||
pub fn get_warning_function() -> WarningFunction { | ||
unsafe { WARNING_FUNCTION.unwrap_or(eprintln) } | ||
} | ||
#[macro_export] | ||
macro_rules! polars_warn { | ||
($fmt:literal, $($arg:tt)+) => { | ||
{{ | ||
let func = $crate::get_warning_function(); | ||
func(format!($fmt, $($arg)+).as_ref()) | ||
}} | ||
}; | ||
($($arg:tt)+) => { | ||
polars_warn!("{}", $($arg)+); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters