support sys::set_verbosity
This commit is contained in:
parent
336743738e
commit
c9b566fc11
2 changed files with 43 additions and 1 deletions
0
nixide/src/nix_settings.rs
Normal file
0
nixide/src/nix_settings.rs
Normal file
|
|
@ -1,4 +1,7 @@
|
|||
use crate::errors::ErrorContext;
|
||||
use crate::sys;
|
||||
use crate::util::wrappers::AsInnerPtr as _;
|
||||
use crate::util::{panic_issue, panic_issue_call_failed, wrap};
|
||||
|
||||
/// Verbosity level
|
||||
///
|
||||
|
|
@ -28,7 +31,46 @@ impl From<sys::nix_verbosity> for NixVerbosity {
|
|||
sys::nix_verbosity_NIX_LVL_CHATTY => NixVerbosity::Chatty,
|
||||
sys::nix_verbosity_NIX_LVL_DEBUG => NixVerbosity::Debug,
|
||||
sys::nix_verbosity_NIX_LVL_VOMIT => NixVerbosity::Vomit,
|
||||
_ => panic!("nixide encountered unknown `nix_verbosity` value, please submit this as an issue at https://github.com/cry128/nixide"),
|
||||
value => panic_issue!(
|
||||
"nixide encountered unknown `nix_verbosity` value ({})",
|
||||
value
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<sys::nix_verbosity> for NixVerbosity {
|
||||
fn into(self) -> sys::nix_verbosity {
|
||||
self as sys::nix_verbosity
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the verbosity level.
|
||||
///
|
||||
/// **This function should never fail!**
|
||||
/// A panic would indicate a bug in nixide itself.
|
||||
///
|
||||
/// # Nix C++ API Internals
|
||||
///
|
||||
/// ```cpp
|
||||
/// nix_err nix_set_verbosity(nix_c_context * context, nix_verbosity level)
|
||||
/// {
|
||||
/// if (context)
|
||||
/// context->last_err_code = NIX_OK;
|
||||
/// if (level > NIX_LVL_VOMIT || level < NIX_LVL_ERROR)
|
||||
/// return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Invalid verbosity level");
|
||||
/// try {
|
||||
/// nix::verbosity = static_cast<nix::Verbosity>(level);
|
||||
/// } catch (...) {
|
||||
/// return nix_context_error(context);
|
||||
/// }
|
||||
/// return NIX_OK;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
pub fn set_verbosity(level: NixVerbosity) {
|
||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_set_verbosity(ctx.as_ptr(), level.into());
|
||||
})
|
||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue