diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-19 15:21:54 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-19 15:21:54 -0600 |
| commit | 619984fa33aec8b9629770928c51ee81a3d3a63f (patch) | |
| tree | fa6de3852d08dea6f77ba2549d98b9fcb457309a /azalea-chat/src | |
| parent | befa22c1f3ff0c1f0cb745b3f4e736910c053a8b (diff) | |
| download | azalea-drasl-619984fa33aec8b9629770928c51ee81a3d3a63f.tar.xz | |
Replace lazy_static with once_cell::sync::Lazy (#43)
* Remove lazy_static in azalea-chat
* replace lazy_static with once_cell everywhere
* fix
* fix import
* ignore a clippy warning in shape codegen
Diffstat (limited to 'azalea-chat/src')
| -rwxr-xr-x | azalea-chat/src/component.rs | 25 | ||||
| -rwxr-xr-x | azalea-chat/src/lib.rs | 3 | ||||
| -rwxr-xr-x | azalea-chat/src/style.rs | 22 |
3 files changed, 22 insertions, 28 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index e4c0ab72..882a521a 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -1,17 +1,16 @@ -use std::{ - fmt::Display, - io::{Cursor, Write}, -}; - -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; -use serde::{de, Deserialize, Deserializer}; - use crate::{ base_component::BaseComponent, style::{ChatFormatting, Style}, text_component::TextComponent, translatable_component::{StringOrComponent, TranslatableComponent}, }; +use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use once_cell::sync::Lazy; +use serde::{de, Deserialize, Deserializer}; +use std::{ + fmt::Display, + io::{Cursor, Write}, +}; /// A chat component, basically anything you can see in chat. #[derive(Clone, Debug)] @@ -20,12 +19,10 @@ pub enum Component { Translatable(TranslatableComponent), } -lazy_static! { - pub static ref DEFAULT_STYLE: Style = Style { - color: Some(ChatFormatting::White.try_into().unwrap()), - ..Style::default() - }; -} +pub static DEFAULT_STYLE: Lazy<Style> = Lazy::new(|| Style { + color: Some(ChatFormatting::White.try_into().unwrap()), + ..Style::default() +}); /// A chat component impl Component { diff --git a/azalea-chat/src/lib.rs b/azalea-chat/src/lib.rs index 01f718eb..fd26ee4f 100755 --- a/azalea-chat/src/lib.rs +++ b/azalea-chat/src/lib.rs @@ -1,9 +1,6 @@ //! Things for working with Minecraft chat messages. //! This was inspired by Minecraft and prismarine-chat. -#[macro_use] -extern crate lazy_static; - pub mod base_component; mod component; pub mod style; diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs index 6422d5e4..1243d56f 100755 --- a/azalea-chat/src/style.rs +++ b/azalea-chat/src/style.rs @@ -1,6 +1,7 @@ use std::{collections::HashMap, fmt}; use azalea_buf::McBuf; +use once_cell::sync::Lazy; use serde_json::Value; #[derive(Clone, PartialEq, Eq, Debug)] @@ -28,8 +29,8 @@ impl TextColor { } } -lazy_static! { - static ref LEGACY_FORMAT_TO_COLOR: HashMap<&'static ChatFormatting, TextColor> = { +static LEGACY_FORMAT_TO_COLOR: Lazy<HashMap<&'static ChatFormatting, TextColor>> = + Lazy::new(|| { let mut legacy_format_to_color = HashMap::new(); for formatter in &ChatFormatting::FORMATTERS { if !formatter.is_format() && *formatter != ChatFormatting::Reset { @@ -43,15 +44,14 @@ lazy_static! { } } legacy_format_to_color - }; - static ref NAMED_COLORS: HashMap<String, TextColor> = { - let mut named_colors = HashMap::new(); - for color in LEGACY_FORMAT_TO_COLOR.values() { - named_colors.insert(color.name.clone().unwrap(), color.clone()); - } - named_colors - }; -} + }); +static NAMED_COLORS: Lazy<HashMap<String, TextColor>> = Lazy::new(|| { + let mut named_colors = HashMap::new(); + for color in LEGACY_FORMAT_TO_COLOR.values() { + named_colors.insert(color.name.clone().unwrap(), color.clone()); + } + named_colors +}); pub struct Ansi {} impl Ansi { |
