Skip to content

Commit a635370

Browse files
committed
refactor: migrate derive(Show) to Debug with Show compat impls
1 parent 5e6af61 commit a635370

51 files changed

Lines changed: 807 additions & 118 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

alsa/host.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
///|
2121
pub struct Host {
2222
_unit : Unit
23-
} derive(Show, Eq)
23+
} derive(Debug, Eq)
2424

2525
///|
2626
pub struct Device {
2727
id : String
2828
desc : String?
2929
direction : @core.DeviceDirection
30-
} derive(Show, Eq)
30+
} derive(Debug, Eq)
3131

3232
///|
3333
pub fn default_host() -> Host {

alsa/moon.pkg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
"Milky2018/moon_cpal/core",
3+
"moonbitlang/core/debug",
34
}
45

56
supported_targets = "native"

alsa/pkg.generated.mbti

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package "Milky2018/moon_cpal/alsa"
33

44
import {
55
"Milky2018/moon_cpal/core",
6+
"moonbitlang/core/debug",
67
}
78

89
// Values
@@ -19,7 +20,7 @@ pub struct Device {
1920
id : String
2021
desc : String?
2122
direction : @core.DeviceDirection
22-
} derive(Eq, Show)
23+
} derive(Eq, @debug.Debug)
2324
pub fn Device::build_input_stream(Self, @core.StreamConfig, (@core.Data, @core.InputCallbackInfo) -> Unit, (@core.StreamError) -> Unit, @core.Duration?) -> Stream raise @core.BuildStreamError
2425
pub fn Device::build_input_stream_raw(Self, @core.StreamConfig, @core.SampleFormat, (@core.Data, @core.InputCallbackInfo) -> Unit, (@core.StreamError) -> Unit, @core.Duration?) -> Stream raise @core.BuildStreamError
2526
pub fn Device::build_output_stream(Self, @core.StreamConfig, (@core.Data, @core.OutputCallbackInfo) -> Unit, (@core.StreamError) -> Unit, @core.Duration?) -> Stream raise @core.BuildStreamError
@@ -33,13 +34,15 @@ pub fn Device::supported_input_configs(Self) -> Array[@core.SupportedStreamConfi
3334
pub fn Device::supported_output_configs(Self) -> Array[@core.SupportedStreamConfigRange] raise @core.SupportedStreamConfigsError
3435
pub fn Device::supports_input(Self) -> Bool
3536
pub fn Device::supports_output(Self) -> Bool
37+
pub impl Show for Device
3638

3739
pub struct Host {
3840
_unit : Unit
39-
} derive(Eq, Show)
41+
} derive(Eq, @debug.Debug)
4042
pub fn Host::default_input_device(Self) -> Device?
4143
pub fn Host::default_output_device(Self) -> Device?
4244
pub fn Host::devices(Self) -> Array[Device]
45+
pub impl Show for Host
4346

4447
pub struct Stream {
4548
kind : StreamKind
@@ -51,11 +54,13 @@ pub fn Stream::pause(Self) -> Unit raise @core.PauseStreamError
5154
pub fn Stream::play(Self) -> Unit raise @core.PlayStreamError
5255
pub impl Eq for Stream
5356
pub impl Show for Stream
57+
pub impl @debug.Debug for Stream
5458

5559
pub enum StreamKind {
5660
Output
5761
Input
58-
} derive(Eq, Show)
62+
} derive(Eq, @debug.Debug)
63+
pub impl Show for StreamKind
5964

6065
type StreamOwner
6166

alsa/show_compat.mbt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2025 International Digital Economy Academy
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
///|
16+
fn[T : @debug.Debug] show_from_debug(value : T, logger : &Logger) -> Unit {
17+
let rendered = @debug.render(@debug.Debug::to_repr(value))
18+
logger.write_string(
19+
rendered
20+
.replace_all(old="{ ", new="{")
21+
.replace_all(old=" }", new="}"),
22+
)
23+
}
24+
25+
///|
26+
pub impl Show for Host with output(self : Host, logger : &Logger) -> Unit {
27+
show_from_debug(self, logger)
28+
}
29+
30+
///|
31+
pub impl Show for Device with output(self : Device, logger : &Logger) -> Unit {
32+
show_from_debug(self, logger)
33+
}
34+
35+
///|
36+
pub impl Show for StreamKind with output(
37+
self : StreamKind,
38+
logger : &Logger,
39+
) -> Unit {
40+
show_from_debug(self, logger)
41+
}

alsa/stream_types.mbt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
pub enum StreamKind {
2424
Output
2525
Input
26-
} derive(Show, Eq)
26+
} derive(Debug, Eq)
2727

2828
///|
2929
// An external object that owns native stream resources.
@@ -44,6 +44,11 @@ pub impl Eq for Stream with equal(self : Stream, other : Stream) -> Bool {
4444
self.kind == other.kind && self.handle == other.handle
4545
}
4646

47+
///|
48+
pub impl @debug.Debug for Stream with to_repr(self : Stream) -> @debug.Repr {
49+
@debug.Debug::to_repr((self.kind, self.handle))
50+
}
51+
4752
///|
4853
pub impl Show for Stream with output(self : Stream, logger : &Logger) -> Unit {
4954
logger.write_string("\{self.kind}(\{self.handle})")

core/cpal_callback_info.mbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct InputStreamTimestamp {
2828
callback : StreamInstant,
2929
capture : StreamInstant,
3030
) -> InputStreamTimestamp
31-
} derive(Show, Eq)
31+
} derive(Debug, Eq)
3232

3333
///|
3434
pub fn InputStreamTimestamp::new(
@@ -62,7 +62,7 @@ pub struct OutputStreamTimestamp {
6262
callback : StreamInstant,
6363
playback : StreamInstant,
6464
) -> OutputStreamTimestamp
65-
} derive(Show, Eq)
65+
} derive(Debug, Eq)
6666

6767
///|
6868
pub fn OutputStreamTimestamp::new(
@@ -92,7 +92,7 @@ pub struct InputCallbackInfo {
9292
timestamp : InputStreamTimestamp
9393

9494
fn new(timestamp : InputStreamTimestamp) -> InputCallbackInfo
95-
} derive(Show, Eq)
95+
} derive(Debug, Eq)
9696

9797
///|
9898
pub fn InputCallbackInfo::new(
@@ -114,7 +114,7 @@ pub struct OutputCallbackInfo {
114114
timestamp : OutputStreamTimestamp
115115

116116
fn new(timestamp : OutputStreamTimestamp) -> OutputCallbackInfo
117-
} derive(Show, Eq)
117+
} derive(Debug, Eq)
118118

119119
///|
120120
pub fn OutputCallbackInfo::new(

core/cpal_data.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct Data {
3232
bytes : FixedArray[Byte]
3333

3434
fn new(sample_format : SampleFormat, bytes : FixedArray[Byte]) -> Data
35-
} derive(Show, Eq)
35+
} derive(Debug, Eq)
3636

3737
///|
3838
pub fn Data::new(

core/cpal_device_description.mbt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum DeviceType {
3030
Tuner
3131
Virtual
3232
Unknown
33-
} derive(Show, Eq)
33+
} derive(Debug, Eq)
3434

3535
///|
3636
pub fn DeviceType::speaker() -> DeviceType {
@@ -103,7 +103,7 @@ pub enum InterfaceType {
103103
DisplayPort
104104
Aggregate
105105
Unknown
106-
} derive(Show, Eq)
106+
} derive(Debug, Eq)
107107

108108
///|
109109
pub fn InterfaceType::built_in() -> InterfaceType {
@@ -181,7 +181,7 @@ pub enum DeviceDirection {
181181
Output
182182
Duplex
183183
Unknown
184-
} derive(Show, Eq)
184+
} derive(Debug, Eq)
185185

186186
///|
187187
pub fn DeviceDirection::input() -> DeviceDirection {
@@ -224,7 +224,7 @@ pub struct DeviceDescription {
224224
address? : String?,
225225
extended? : Array[String],
226226
) -> DeviceDescription
227-
} derive(Show, Eq)
227+
} derive(Debug, Eq)
228228

229229
///|
230230
pub fn DeviceDescription::new(
@@ -389,7 +389,7 @@ pub struct DeviceDescriptionBuilder {
389389
extended : Array[String]
390390

391391
fn new(name : String) -> DeviceDescriptionBuilder
392-
} derive(Show, Eq)
392+
} derive(Debug, Eq)
393393

394394
///|
395395
pub fn DeviceDescriptionBuilder::new(name : String) -> DeviceDescriptionBuilder {

core/cpal_device_id.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
pub suberror DeviceIdError {
2222
UnsupportedPlatform
2323
BackendSpecific(BackendSpecificError)
24-
} derive(Show, Eq)
24+
} derive(Debug, Eq)
2525

2626
///|
2727
pub fn device_id_error_unsupported_platform() -> DeviceIdError {
@@ -48,7 +48,7 @@ pub struct DeviceId {
4848
device_id : String
4949

5050
fn new(host_id : HostId, device_id : String) -> DeviceId
51-
} derive(Show, Eq)
51+
} derive(Debug, Eq)
5252

5353
///|
5454
pub fn DeviceId::new(host_id : HostId, device_id : String) -> DeviceId {

core/cpal_error.mbt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct BackendSpecificError {
2222
description : String
2323

2424
fn new(description : String) -> BackendSpecificError
25-
} derive(Show, Eq)
25+
} derive(Debug, Eq)
2626

2727
///|
2828
pub fn BackendSpecificError::new(description : String) -> BackendSpecificError {
@@ -46,7 +46,7 @@ pub suberror DefaultStreamConfigError {
4646
DeviceBusy
4747
StreamTypeNotSupported
4848
BackendSpecific(BackendSpecificError)
49-
} derive(Show, Eq)
49+
} derive(Debug, Eq)
5050

5151
///|
5252
pub fn DefaultStreamConfigError::to_string(
@@ -70,7 +70,7 @@ pub suberror SupportedStreamConfigsError {
7070
DeviceBusy
7171
InvalidArgument
7272
BackendSpecific(BackendSpecificError)
73-
} derive(Show, Eq)
73+
} derive(Debug, Eq)
7474

7575
///|
7676
pub fn SupportedStreamConfigsError::to_string(
@@ -91,7 +91,7 @@ pub fn SupportedStreamConfigsError::to_string(
9191
/// An error that might occur while attempting to enumerate devices.
9292
pub suberror DevicesError {
9393
BackendSpecific(BackendSpecificError)
94-
} derive(Show, Eq)
94+
} derive(Debug, Eq)
9595

9696
///|
9797
pub fn DevicesError::to_string(self : DevicesError) -> String {
@@ -104,7 +104,7 @@ pub fn DevicesError::to_string(self : DevicesError) -> String {
104104
/// An error that may occur while attempting to retrieve a device name.
105105
pub suberror DeviceNameError {
106106
BackendSpecific(BackendSpecificError)
107-
} derive(Show, Eq)
107+
} derive(Debug, Eq)
108108

109109
///|
110110
pub fn DeviceNameError::to_string(self : DeviceNameError) -> String {
@@ -122,7 +122,7 @@ pub suberror BuildStreamError {
122122
InvalidArgument
123123
StreamIdOverflow
124124
BackendSpecific(BackendSpecificError)
125-
} derive(Show, Eq)
125+
} derive(Debug, Eq)
126126

127127
///|
128128
pub fn BuildStreamError::to_string(self : BuildStreamError) -> String {
@@ -145,7 +145,7 @@ pub fn BuildStreamError::to_string(self : BuildStreamError) -> String {
145145
pub suberror PlayStreamError {
146146
DeviceNotAvailable
147147
BackendSpecific(BackendSpecificError)
148-
} derive(Show, Eq)
148+
} derive(Debug, Eq)
149149

150150
///|
151151
pub fn PlayStreamError::to_string(self : PlayStreamError) -> String {
@@ -160,7 +160,7 @@ pub fn PlayStreamError::to_string(self : PlayStreamError) -> String {
160160
pub suberror PauseStreamError {
161161
DeviceNotAvailable
162162
BackendSpecific(BackendSpecificError)
163-
} derive(Show, Eq)
163+
} derive(Debug, Eq)
164164

165165
///|
166166
pub fn PauseStreamError::to_string(self : PauseStreamError) -> String {
@@ -177,7 +177,7 @@ pub suberror StreamError {
177177
StreamInvalidated
178178
BufferUnderrun
179179
BackendSpecific(BackendSpecificError)
180-
} derive(Show, Eq)
180+
} derive(Debug, Eq)
181181

182182
///|
183183
pub fn StreamError::to_string(self : StreamError) -> String {

0 commit comments

Comments
 (0)