mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Use enums instead of bools in public API
Replace the boolean parameters for including user metadata and evaluating conditions with MergeMode and EvalMode enums. The C++ and Python wrappers still use booleans because they're more constrained than enums in those languages, which can be given invalid values.
This commit is contained in:
+25
-5
@@ -3,7 +3,7 @@ use std::{
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
use libloot::{WriteMode, error::DatabaseLockPoisonError};
|
||||
use libloot::{EvalMode, MergeMode, WriteMode, error::DatabaseLockPoisonError};
|
||||
use libloot_ffi_errors::UnsupportedEnumValueError;
|
||||
use pyo3::{
|
||||
Bound, PyResult, pyclass, pymethods,
|
||||
@@ -113,7 +113,7 @@ impl Database {
|
||||
self.0
|
||||
.write()
|
||||
.map_err(DatabaseLockPoisonError::from)?
|
||||
.general_messages(evaluate_conditions)
|
||||
.general_messages(to_eval_mode(evaluate_conditions))
|
||||
.map(|v| v.into_iter().map(Into::into).collect())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
@@ -123,7 +123,7 @@ impl Database {
|
||||
.0
|
||||
.read()
|
||||
.map_err(DatabaseLockPoisonError::from)?
|
||||
.groups(include_user_metadata)
|
||||
.groups(to_merge_mode(include_user_metadata))
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect())
|
||||
@@ -172,7 +172,11 @@ impl Database {
|
||||
self.0
|
||||
.read()
|
||||
.map_err(DatabaseLockPoisonError::from)?
|
||||
.plugin_metadata(plugin_name, include_user_metadata, evaluate_conditions)
|
||||
.plugin_metadata(
|
||||
plugin_name,
|
||||
to_merge_mode(include_user_metadata),
|
||||
to_eval_mode(evaluate_conditions),
|
||||
)
|
||||
.map(|p| p.map(Into::into))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
@@ -185,7 +189,7 @@ impl Database {
|
||||
self.0
|
||||
.read()
|
||||
.map_err(DatabaseLockPoisonError::from)?
|
||||
.plugin_user_metadata(plugin_name, evaluate_conditions)
|
||||
.plugin_user_metadata(plugin_name, to_eval_mode(evaluate_conditions))
|
||||
.map(|p| p.map(Into::into))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
@@ -224,6 +228,22 @@ impl From<Arc<RwLock<libloot::Database>>> for Database {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_eval_mode(value: bool) -> EvalMode {
|
||||
if value {
|
||||
EvalMode::Evaluate
|
||||
} else {
|
||||
EvalMode::DoNotEvaluate
|
||||
}
|
||||
}
|
||||
|
||||
fn to_merge_mode(value: bool) -> MergeMode {
|
||||
if value {
|
||||
MergeMode::WithUserMetadata
|
||||
} else {
|
||||
MergeMode::WithoutUserMetadata
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(eq, ord, frozen, hash, str = "{0:?}")]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
#[repr(transparent)]
|
||||
|
||||
Reference in New Issue
Block a user