Skip to content

Commit

Permalink
由于GitHub-Actions的Rust版本限制, 进行一些小改
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Oct 17, 2023
1 parent 2966a7b commit a292fd6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mindustry_logic_bang_lang"
version = "0.12.5"
version = "0.12.6"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
23 changes: 22 additions & 1 deletion src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,6 @@ pub trait Compile {
}
}

#[derive(Debug)]
pub struct CompileMeta {
/// 标记与`id`的映射关系表
tags_map: HashMap<String, usize>,
Expand All @@ -2142,6 +2141,28 @@ pub struct CompileMeta {
const_expand_tag_name_map: Vec<HashMap<Var, Var>>,
value_binds: HashMap<(Var, Var), Var>,
}
impl Debug for CompileMeta {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// 为适应GitHub Rust Actions的老版本Rust, 暂时将Debug宏手动实现
struct DotDot;
impl Debug for DotDot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "..")
}
}
f.debug_struct("CompileMeta")
.field("tags_map", &self.tags_map)
.field("tag_count", &self.tag_count)
.field("tag_codes", &self.tag_codes)
.field("tmp_var_count", &self.tmp_var_count.counter())
.field("const_var_namespace", &self.const_var_namespace)
.field("dexp_result_handles", &self.dexp_result_handles)
.field("tmp_tag_count", &self.tmp_tag_count.counter())
.field("const_expand_tag_name_map", &self.const_expand_tag_name_map)
.field("value_binds", &self.value_binds)
.finish()
}
}
impl Default for CompileMeta {
fn default() -> Self {
Self::with_tag_codes(TagCodes::new())
Expand Down
2 changes: 1 addition & 1 deletion tools/utils/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "utils"
version = "0.1.1"
version = "0.1.2"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
24 changes: 23 additions & 1 deletion tools/utils/src/counter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Debug;

/// 一个负责获取结果并自增的结构
/// # Examples
/// ```
Expand All @@ -12,12 +14,26 @@
/// assert_eq!(counter.get(), "__2");
/// assert_eq!(counter.get(), "__3");
/// ```
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
pub struct Counter<F, T = usize>
{
counter: T,
getter: F,
}
impl<F, T: Debug> Debug for Counter<F, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
struct DotDot;
impl Debug for DotDot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "..")
}
}
f.debug_struct("Counter")
.field("counter", &self.counter)
.field("getter", &DotDot)
.finish()
}
}

impl<F, R, T> Counter<F, T>
where F: FnMut(&mut T) -> R
Expand All @@ -29,9 +45,15 @@ where F: FnMut(&mut T) -> R
}
}

/// 获取更新函数返回的值
pub fn get(&mut self) -> R {
(self.getter)(&mut self.counter)
}

/// 返回内部值
pub fn counter(&self) -> &T {
&self.counter
}
}

impl<F, R, T> Counter<F, T>
Expand Down

0 comments on commit a292fd6

Please sign in to comment.