Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text API redesign #417

Merged
merged 12 commits into from
Jul 22, 2023
Merged

Text API redesign #417

merged 12 commits into from
Jul 22, 2023

Conversation

PonasKovas
Copy link
Contributor

Objective

Solution

  • Redesign Color to make reset representable, separate NormalColor and RgbColor.
  • Make contents of Text, InnerText, TextContent, etc public.
  • Redesign TextFormat trait to allow mutating a &mut Text without cloning.
  • Create IntoText trait which is basically the same as Into<Cow<'a, Text>> (can't implement the latter because of Rust's trait coherence rules)
  • Fallback to normal colors instead of webcolors for pre-1.16 server list pings.

I couldn't figure out a good way to meaningfully reduce the size of TextInner so that it wouldn't need to be boxed in Text,

}

impl NormalColor {
pub const fn as_hex_digit(self) -> char {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub const fn as_hex_digit(self) -> char {
pub const fn to_hex_digit(self) -> char {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since NormalColor is Copy maybe the best solution here would be simple fn hex_digit(self) and fn name(self) without either as or to to avoid confusion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would associate fn hex_digit(self) with an accessor while fn to_hex_digit(self) with a function that does some work to convert to another type.

https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv

crates/valence_core/src/text/color.rs Outdated Show resolved Hide resolved
crates/valence_core/src/text/color.rs Outdated Show resolved Hide resolved
crates/valence_core/src/text/into_text.rs Outdated Show resolved Hide resolved
crates/valence_core/src/text/text_format.rs Outdated Show resolved Hide resolved
@PonasKovas
Copy link
Contributor Author

Thanks for the reviews, sorry for my delayed response. Should be good to go now.

@rj00a rj00a merged commit 9c599dd into valence-rs:main Jul 22, 2023
13 checks passed
@PonasKovas PonasKovas deleted the text branch July 23, 2023 10:13
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.

Redesign Text API
3 participants