diff --git a/examples/twitch.rs b/examples/twitch.rs index acfa89f..37d4fe8 100644 --- a/examples/twitch.rs +++ b/examples/twitch.rs @@ -14,7 +14,7 @@ use std::env::args; -use brainrot::{twitch, TwitchChat, TwitchChatEvent}; +use brainrot::{TwitchChat, TwitchChatEvent, twitch}; use futures_util::StreamExt; #[tokio::main] diff --git a/rustfmt.toml b/rustfmt.toml index b0dae71..8d861c5 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,5 @@ edition = "2021" -version = "Two" +style_edition = "2024" unstable_features = true max_width = 160 @@ -24,6 +24,7 @@ single_line_if_else_max_width = 96 reorder_imports = true group_imports = "StdExternalCrate" +imports_granularity = "Crate" reorder_modules = true trailing_comma = "Never" match_block_trailing_comma = false diff --git a/src/twitch/event.rs b/src/twitch/event.rs index 82900af..21aa9be 100644 --- a/src/twitch/event.rs +++ b/src/twitch/event.rs @@ -21,7 +21,7 @@ use chrono::{DateTime, TimeZone, Utc}; use irc::proto::{Command, Response}; use uuid::Uuid; -use crate::util::{get_utf8_slice, MapNonempty}; +use crate::util::{MapNonempty, get_utf8_slice}; /// A user's role. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -125,19 +125,16 @@ pub(crate) fn to_chat_event(message: irc::proto::Message) -> Option { .collect::>(); let (username, user_display_name) = match message.prefix? { - irc::proto::Prefix::Nickname(n1, n2, _) => ( - n1, - match tags.remove("display-name") { - Some(display_name) => { - if display_name.is_empty() { - n2 - } else { - display_name - } + irc::proto::Prefix::Nickname(n1, n2, _) => (n1, match tags.remove("display-name") { + Some(display_name) => { + if display_name.is_empty() { + n2 + } else { + display_name } - None => n2 } - ), + None => n2 + }), _ => return None }; diff --git a/src/twitch/mod.rs b/src/twitch/mod.rs index 86b3ed2..1e2a1f4 100644 --- a/src/twitch/mod.rs +++ b/src/twitch/mod.rs @@ -19,7 +19,7 @@ use std::{ use futures_util::{Stream, StreamExt}; use irc::{ - client::{prelude::Config, Client, ClientStream}, + client::{Client, ClientStream, prelude::Config}, proto::Capability }; diff --git a/src/youtube/context.rs b/src/youtube/context.rs index 14d2cde..f9fca47 100644 --- a/src/youtube/context.rs +++ b/src/youtube/context.rs @@ -18,11 +18,10 @@ use regex::Regex; use url::Url; use super::{ - get_http_client, + Error, get_http_client, types::streams_page::{ FeedContentsRenderer, PageContentsRenderer, RichGridItem, RichItemContent, TabItemRenderer, ThumbnailOverlay, VideoTimeStatus, YouTubeInitialData - }, - Error + } }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/src/youtube/mod.rs b/src/youtube/mod.rs index f98cee1..222103c 100644 --- a/src/youtube/mod.rs +++ b/src/youtube/mod.rs @@ -30,8 +30,8 @@ pub use self::{ context::{ChannelSearchOptions, ChatContext, LiveStreamStatus}, error::Error, types::{ - get_live_chat::{Action, ChatItem, MessageRendererBase}, - ImageContainer, LocalizedRun, LocalizedText, Thumbnail, UnlocalizedText + ImageContainer, LocalizedRun, LocalizedText, Thumbnail, UnlocalizedText, + get_live_chat::{Action, ChatItem, MessageRendererBase} } }; use self::{ diff --git a/src/youtube/signaler.rs b/src/youtube/signaler.rs index 3c686f8..6d9c56e 100644 --- a/src/youtube/signaler.rs +++ b/src/youtube/signaler.rs @@ -32,14 +32,14 @@ use std::{collections::HashMap, io::BufRead, iter}; use rand::Rng; -use reqwest::{header, Response}; +use reqwest::{Response, header}; use simd_json::{ - base::{ValueAsContainer, ValueAsScalar}, - OwnedValue + OwnedValue, + base::{ValueAsContainer, ValueAsScalar} }; use url::Url; -use super::{util::SimdJsonResponseBody, Error}; +use super::{Error, util::SimdJsonResponseBody}; const GCM_SIGNALER_SRQE: &str = "https://signaler-pa.youtube.com/punctual/v1/chooseServer"; const GCM_SIGNALER_PSUB: &str = "https://signaler-pa.youtube.com/punctual/multi-watch/channel"; @@ -135,21 +135,18 @@ impl SignalerChannelInner { pub async fn get_session_stream(&self) -> Result { Ok(super::get_http_client() - .get(Url::parse_with_params( - GCM_SIGNALER_PSUB, - [ - ("VER", "8"), - ("gsessionid", self.gsessionid.as_ref().unwrap()), - ("key", &self.tango_key), - ("RID", "rpc"), - ("SID", self.sid.as_ref().unwrap()), - ("AID", &self.aid.to_string()), - ("CI", "0"), - ("TYPE", "xmlhttp"), - ("zx", &Self::gen_zx()), - ("t", "1") - ] - )?) + .get(Url::parse_with_params(GCM_SIGNALER_PSUB, [ + ("VER", "8"), + ("gsessionid", self.gsessionid.as_ref().unwrap()), + ("key", &self.tango_key), + ("RID", "rpc"), + ("SID", self.sid.as_ref().unwrap()), + ("AID", &self.aid.to_string()), + ("CI", "0"), + ("TYPE", "xmlhttp"), + ("zx", &Self::gen_zx()), + ("t", "1") + ])?) .header(header::CONNECTION, "keep-alive") .send() .await?) diff --git a/src/youtube/types/get_live_chat.rs b/src/youtube/types/get_live_chat.rs index 2d46e3a..bb27ce3 100644 --- a/src/youtube/types/get_live_chat.rs +++ b/src/youtube/types/get_live_chat.rs @@ -18,11 +18,10 @@ use serde_aux::prelude::*; use simd_json::{base::ValueAsContainer, derived::ValueObjectAccessAsScalar}; use url::Url; -use super::{deserialize_datetime_utc_from_microseconds, Accessibility, CommandMetadata, Icon, ImageContainer, LocalizedText, UnlocalizedText}; +use super::{Accessibility, CommandMetadata, Icon, ImageContainer, LocalizedText, UnlocalizedText, deserialize_datetime_utc_from_microseconds}; use crate::youtube::{ - get_http_client, - util::{SimdJsonRequestBody, SimdJsonResponseBody}, - ChatContext, Error, TANGO_LIVE_ENDPOINT, TANGO_REPLAY_ENDPOINT + ChatContext, Error, TANGO_LIVE_ENDPOINT, TANGO_REPLAY_ENDPOINT, get_http_client, + util::{SimdJsonRequestBody, SimdJsonResponseBody} }; #[derive(Serialize, Debug)] @@ -68,10 +67,10 @@ impl GetLiveChatResponse { pub async fn fetch(options: &ChatContext, continuation: impl AsRef) -> Result { let body = GetLiveChatRequestBody::new(continuation.as_ref(), &options.client_version, "WEB"); Ok(get_http_client() - .post(Url::parse_with_params( - if options.live_status.updates_live() { TANGO_LIVE_ENDPOINT } else { TANGO_REPLAY_ENDPOINT }, - [("key", options.api_key.as_str()), ("prettyPrint", "false")] - )?) + .post(Url::parse_with_params(if options.live_status.updates_live() { TANGO_LIVE_ENDPOINT } else { TANGO_REPLAY_ENDPOINT }, [ + ("key", options.api_key.as_str()), + ("prettyPrint", "false") + ])?) .simd_json(&body)? .send() .await? diff --git a/src/youtube/types/mod.rs b/src/youtube/types/mod.rs index 5a4bd07..e07cdcf 100644 --- a/src/youtube/types/mod.rs +++ b/src/youtube/types/mod.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use serde::{de::Error, Deserialize, Deserializer}; +use serde::{Deserialize, Deserializer, de::Error}; use serde_aux::field_attributes::deserialize_number_from_string; use simd_json::OwnedValue; diff --git a/src/youtube/util.rs b/src/youtube/util.rs index 1293102..dc566d8 100644 --- a/src/youtube/util.rs +++ b/src/youtube/util.rs @@ -15,7 +15,7 @@ use std::future::Future; use reqwest::{RequestBuilder, Response}; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use super::Error;