Skip to content

Commit ef0ca2f

Browse files
committed
log: mw_log_fmt implementation
- Replacement for `core::fmt`. - Partial implementation of common types. - Internal `ScoreDebug` implementation helpers. - Unit tests.
1 parent 696d955 commit ef0ca2f

File tree

19 files changed

+1594
-89
lines changed

19 files changed

+1594
-89
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
150
105105
]
106106
},
107+
"rust-analyzer.cargo.features": [
108+
"qm"
109+
],
107110
"rust-analyzer.cargo.cfgs": [
108111
"!miri"
109112
],

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22
resolver = "2"
33
# Split to default members without tests and examples.
44
# Used when executing cargo from project root.
5-
default-members = [
6-
"src/containers",
7-
"src/log"
8-
]
5+
default-members = ["src/containers", "src/log/mw_log_fmt"]
96
# Include tests and examples as a member for IDE support and Bazel builds.
10-
members = [
11-
"src/containers",
12-
"src/log"
13-
]
7+
members = ["src/containers", "src/log/mw_log_fmt"]
148

159

1610
[workspace.package]
@@ -21,6 +15,7 @@ authors = ["S-CORE Contributors"]
2115

2216

2317
[workspace.dependencies]
18+
mw_log_fmt = { path = "src/log/mw_log_fmt" }
2419

2520

2621
[workspace.lints.clippy]
@@ -30,3 +25,4 @@ alloc_instead_of_core = "warn"
3025

3126
[workspace.lints.rust]
3227
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] }
28+
missing_docs = "warn"

docs/module/log/architecture/_assets/interface.puml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,12 @@ package log <<component>> {
4747
+fmt(&self, f: &mut dyn ScoreWrite, spec: &FormatSpec) : Result
4848
}
4949

50-
+interface ScoreDisplay <<trait>> {
51-
+fmt(&self, f: &mut dyn ScoreWrite, spec: &FormatSpec) : Result
52-
}
53-
5450
class mw_log_fmt <<module>> {
5551
+write(output: &mut dyn ScoreWrite, args: Arguments<'_>) : Result
5652

5753
+score_write!(format_string: &str, args...) : Result
5854
+score_writeln!(format_string: &str, args...) : Result
5955
}
60-
61-
ScoreDebug -[hidden]down- ScoreDisplay
62-
ScoreDisplay -[hidden]down- mw_log_fmt
63-
6456
}
6557

6658
mw_log -- Level
@@ -69,6 +61,4 @@ package log <<component>> {
6961
mw_log -right- mw_log_fmt
7062
}
7163

72-
73-
7464
@enduml

docs/module/log/detailed_design/_assets/class_diagram.puml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ package "mw_log_fmt crate" {
161161
-spec: FormatSpec
162162
-_lifetime: PhantomData<&'a ()>
163163

164-
+new_debug(value: &ScoreDebug, spec: FormatSpec) : Self
165-
+new_display(value: &ScoreDisplay, spec: FormatSpec) : Self
164+
+new(value: &ScoreDebug, spec: FormatSpec) : Self
166165

167166
+fmt(&self, f: &mut dyn ScoreWrite, spec: &FormatSpec) : Result
168167
}
@@ -186,17 +185,11 @@ package "mw_log_fmt crate" {
186185
+fmt(&self, f: &mut dyn ScoreWrite, spec: &FormatSpec) : Result
187186
}
188187

189-
+interface ScoreDisplay <<trait>> {
190-
+fmt(&self, f: &mut dyn ScoreWrite, spec: &FormatSpec) : Result
191-
}
192-
193-
' Placeholders are dependent on implementations provided by "Score*" traits.
188+
' Placeholders are dependent on "ScoreDebug" trait implementations.
194189
Placeholder --> ScoreDebug
195-
Placeholder --> ScoreDisplay
196190

197-
' All trait implementations rely on "ScoreWrite".
191+
' Trait implementations rely on "ScoreWrite".
198192
ScoreDebug --> ScoreWrite
199-
ScoreDisplay --> ScoreWrite
200193

201194
class mw_log_fmt <<module>> {
202195
+write(output: &mut dyn ScoreWrite, args: Arguments<'_>) : Result

docs/module/log/detailed_design/_assets/log_op.puml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ end box
1717

1818
box #LightYellow
1919
participant "mw_log_fmt\n<<module>>" as mw_log_fmt
20-
participant "ConcreteType\n<<ScoreDisplay implementation>>" as score_display
2120
participant "ConcreteType\n<<ScoreDebug implementation>>" as score_debug
2221
end box
2322

@@ -54,13 +53,9 @@ else log-level-check-passed
5453
mw_log_fmt -> writer : write_str()
5554
writer --> mw_log_fmt
5655
else is-placeholder
57-
alt display-requested
58-
mw_log_fmt -> score_display : fmt()
59-
score_display --> mw_log_fmt
60-
else debug-requested
61-
mw_log_fmt -> score_debug : fmt()
62-
score_debug --> mw_log_fmt
63-
end
56+
mw_log_fmt -> score_debug : fmt()
57+
score_debug --> mw_log_fmt
58+
6459
mw_log_fmt -> writer : write_<type>()
6560
writer --> mw_log_fmt
6661
end

src/log/BUILD

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +0,0 @@
1-
# *******************************************************************************
2-
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3-
#
4-
# See the NOTICE file(s) distributed with this work for additional
5-
# information regarding copyright ownership.
6-
#
7-
# This program and the accompanying materials are made available under the
8-
# terms of the Apache License Version 2.0 which is available at
9-
# https://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# SPDX-License-Identifier: Apache-2.0
12-
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14-
15-
rust_library(
16-
name = "log",
17-
srcs = glob(["src/**/*.rs"]),
18-
visibility = ["//visibility:public"],
19-
)
20-
21-
rust_test(
22-
name = "log_tests",
23-
crate = ":log",
24-
)

src/log/Cargo.toml

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/log/mw_log_fmt/BUILD

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14+
15+
rust_library(
16+
name = "mw_log_fmt",
17+
srcs = glob(["**/*.rs"]),
18+
crate_features = ["qm"],
19+
# TODO: expose required interface through `mw_log`.
20+
visibility = ["//visibility:public"],
21+
)
22+
23+
rust_test(
24+
name = "tests",
25+
crate = "mw_log_fmt",
26+
tags = [
27+
"unit_tests",
28+
"ut",
29+
],
30+
)

src/log/mw_log_fmt/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
[package]
15+
name = "mw_log_fmt"
16+
version.workspace = true
17+
authors.workspace = true
18+
readme.workspace = true
19+
edition.workspace = true
20+
21+
[lib]
22+
path = "lib.rs"
23+
24+
[features]
25+
qm = []
26+
27+
[lints]
28+
workspace = true

0 commit comments

Comments
 (0)