From 5b6deeab83dc9366177af2f2adc194cf5eee820c Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:27:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E4=BF=AE=E5=A4=8D=E3=80=8C?= =?UTF-8?q?=E7=9F=AD=E6=B5=AE=E7=82=B9=E7=B2=BE=E5=BA=A6=E3=80=8D=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=9A=84=E5=90=88=E5=B9=B6=E4=B8=A2=E5=A4=B1=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现在启动参数的「短浮点精度」也将在「与其它配置合并」时合并(取有值的一方);优化有关宏,便于在编译时发现字段缺失(新增字段而未指定其合并时行为)的情况 --- src/bin/babelnar_cli/vm_config.rs | 53 +++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/bin/babelnar_cli/vm_config.rs b/src/bin/babelnar_cli/vm_config.rs index b4b3f6b..99fe6f8 100644 --- a/src/bin/babelnar_cli/vm_config.rs +++ b/src/bin/babelnar_cli/vm_config.rs @@ -86,10 +86,39 @@ pub const SUPPORTED_CONFIG_EXTENSIONS: &[&str] = &["hjson", "json"]; macro_rules! coalesce_clones { { // 合并的方向 - $other:ident => $this:ident; + $self_type:ty: $other:ident => $this:ident; // 要合并的键 - $($field:ident)* - } => { $( $this.$field.coalesce_clone(&$other.$field); )* }; + $( $field:ident $( => $code:tt)? )* + } => { + // 模式匹配提取字段 + // * 🎯保证考虑了所有字段(避免新增字段遗漏) + let Self { + $($field: _),* + } = &$other; + // 逐个拷贝 / 执行其它代码(亦可直接使用字段) + $( + coalesce_clones! { + @FIELD + $this => $other, + $field $($code)? + }; + )* + }; + { // 简单合并字段 + @FIELD + $this:ident => $other:ident, + $field:ident + } => { + $this.$field.coalesce_clone(&$other.$field); + }; + { // 执行其它代码 + @FIELD + $this:ident => $other:ident, + $field:ident + $code:tt + } => { + $code + }; } /// NAVM虚拟机(运行时)启动配置 @@ -569,18 +598,23 @@ impl LaunchConfig { pub fn merge_from(&mut self, other: &Self) { // 合并所有内部Option | 使用工具宏简化语法 coalesce_clones! { - other => self; + Self: other => self; translators - // command // ! 此键需递归处理 websocket prelude_nal user_input input_mode auto_restart strict_mode - } - // 递归合并所有【含有可选键】的值 - LaunchConfigCommand::merge_as_key(&mut self.command, &other.command); + short_float_epoch + // 递归合并所有【含有可选键】的值 + command => { + LaunchConfigCommand::merge_as_key(&mut self.command, &other.command); + } + // 以下字段仍然保留自身数据 + config_path => {} + description => {} + }; } } @@ -589,9 +623,10 @@ impl LaunchConfigCommand { /// * 🚩`Some(..)` => `None` pub fn merge_from(&mut self, other: &Self) { coalesce_clones! { - other => self; + Self: other => self; cmd_args current_dir + cmd => {} } }