Skip to content

replace buggy Display implementation for Pronounce with Debug trait - #820

Merged
NSoiffer merged 5 commits into
daisy:mainfrom
moritz-gross:replace-fmt-Display-for-Pronounce
Sep 27, 2026
Merged

NSoiffer merged 5 commits into
daisy:mainfrom
moritz-gross:replace-fmt-Display-for-Pronounce

Conversation

@moritz-gross

Copy link
Copy Markdown
Collaborator

not 100% sure what is going on here.

impl fmt::Display for Pronounce looks buggy to me, as pronounce: [ is opened 4 times, but only closed once at the end.
And even after fixing it, it looks basically the same as what the Debug trait provides anyway.

to me, the simplest solution is to just use the Debug trait from Rust, whose main difference is explicitly escaping strings with ", as seen in the test.

Generally, having multiple (slightly different) forms of displaying a type is something that has shown not worth it to me in past projects (eg as a source of error like here).
I'm pretty sure there are more spots like this, which I can search for if you agree with me here.

@moritz-gross

moritz-gross commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

ok so cargo build fails as the field eloquence is never used except for the now removed Display trait. Should we just drop it for now, as it's not supported?

error: field `eloquence` is never read
   --> src/tts.rs:117:5
    |
113 | pub struct Pronounce {
    |            --------- field in this struct
...
117 |     eloquence: String,
    |     ^^^^^^^^^
    |
    = note: `Pronounce` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
    = note: `-D dead-code` implied by `-D warnings`
    = help: to override `-D warnings` add `#[expect(dead_code)]` or `#[allow(dead_code)]`

error: could not compile `mathcat` (lib) due to 1 previous error

@NSoiffer

NSoiffer commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

The Display part was just for debugging help, so the unmatched brackets was just a little ugly. However, you are right that it should make use of the DEBUG trait.

"eloquence" is a speech engine used with JAWS... except that JAWS doesn't use it when incorporating MathCAT so it isn't implemented for real. However, the code was set up to read the value if specified as part of a "Pronounce" yaml command (forces pronunciation). Every TTS has different ways of doing that, so translators should list how it is done for each TTS. Very ugly, but I don't know of another way other than allowing a finite list of Pronounce values and interally have the values set up.

Some rule files use "eloquence", so you still need to handle it in build. However, you can comment out the instance variable and change

  "eloquence" => eloquence = as_str_checked(value)?,

to

  "eloquence" =>as_str_checked(value)?,

@moritz-gross

Copy link
Copy Markdown
Collaborator Author

ok, fixed it, I think ?!?
Don't really know much about this topic in general, so feel free to just fix this up and merge it, instead of trying to explain it to me.

@github-actions

Copy link
Copy Markdown
Linux library size: 0.58 MiB (-0.02%)
Revision Release liblibmathcat.so
Base (89d018b) 0.58 MiB (605,448 bytes)
PR (a3ed914) 0.58 MiB (605,312 bytes)
Change -136 bytes (-0.02%)

Built with default features, Rust 1.96.0, and Ubuntu 24.04. Workflow run.

@NSoiffer
NSoiffer merged commit 3bbbd44 into daisy:main Sep 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants