refactor(metassr-html): idiomatic From impls, simplified Display, and modernized builder bounds#104
Open
abhicodes0324 wants to merge 1 commit intometacall:masterfrom
Conversation
… modernized builder bounds Signed-off-by: Abhiswant Chaudhary <abhicodes0324@gmail.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four idiomatic Rust improvements to
metassr-html. No behaviour changes - all existing tests pass and 8 new tests added.Changes
HtmlOutput: Replace custompub fn from(html: &str)withimpl From<String>+impl From<&str>.From<String>moves the value in zero-copy; the old method shadowed the trait without implementing it.Display: Simplifyf.write_fmt(format_args!(…))→write!(f, …).generate(): Fix double allocation -From<String>now takes the ownedformat!("{}", self.template)directly instead of borrowing a.to_string()intermediary.HtmlPropsBuilder: Change setter bounds from&S: ToString + ?Sizedtoimpl Into<String>. Accepts&str,String, andCow<str>at call sites without explicit conversion and moves owned Strings without cloning. Also replaceunwrap_or(&String::new()).to_owned()withunwrap_or_default().Checklist
cargo clippycleancargo fmtapplied