Function try_apply

Source
pub fn try_apply(p: Preferences) -> Result<ApplyOutcome, StorageError>
Expand description

Validate and apply a complete audio/graphics snapshot without persisting it. Invalid fields return StorageError::Invalid before any change. Unchanged settings avoid mixer setters and graphics refresh; runtime drift is repaired. Existing visual policy and explicit URL/environment overrides are preserved.

use ferravex_render::preferences::{self, Preferences};
let previous = preferences::current();
let invalid = Preferences { master: 0.2, lights: 5, ..previous };
assert!(preferences::try_apply(invalid).is_err());
assert_eq!(preferences::current(), previous);
let result = preferences::try_apply(Preferences { master: 0.2, ..previous }).unwrap();
assert!(result.audio_changed);
assert!(!result.graphics_changed);