Skip to content

refactor(metassr-html): idiomatic From impls, simplified Display, and modernized builder bounds#104

Open
abhicodes0324 wants to merge 1 commit intometacall:masterfrom
abhicodes0324:refactor/metassr-html-idiomatic-string-handling
Open

refactor(metassr-html): idiomatic From impls, simplified Display, and modernized builder bounds#104
abhicodes0324 wants to merge 1 commit intometacall:masterfrom
abhicodes0324:refactor/metassr-html-idiomatic-string-handling

Conversation

@abhicodes0324
Copy link
Contributor

Summary

Four idiomatic Rust improvements to metassr-html. No behaviour changes - all existing tests pass and 8 new tests added.

Changes

  • HtmlOutput: Replace custom pub fn from(html: &str) with impl From<String> + impl From<&str>. From<String> moves the value in zero-copy; the old method shadowed the trait without implementing it.
  • Display: Simplify f.write_fmt(format_args!(…))write!(f, …).
  • generate(): Fix double allocation - From<String> now takes the owned format!("{}", self.template) directly instead of borrowing a .to_string() intermediary.
  • HtmlPropsBuilder: Change setter bounds from &S: ToString + ?Sized to impl Into<String>. Accepts &str, String, and Cow<str> at call sites without explicit conversion and moves owned Strings without cloning. Also replace unwrap_or(&String::new()).to_owned() with unwrap_or_default().

Checklist

  • No behaviour changes
  • All existing tests pass
  • 8 new unit tests added
  • cargo clippy clean
  • cargo fmt applied

… modernized builder bounds

Signed-off-by: Abhiswant Chaudhary <abhicodes0324@gmail.com>
@abhicodes0324
Copy link
Contributor Author

Hi @fahdfady @hulxv, please have a look when you get time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant