Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Dec 6, 2024
1 parent ae660bd commit b139bfa
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/json/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl SerializeState {
}
}

impl<'a> std::fmt::Debug for ValueRef<'a> {
impl std::fmt::Debug for ValueRef<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ValueRef::String(s) => write!(f, "String({:?})", s),
Expand Down
2 changes: 1 addition & 1 deletion src/json/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum ValueRef<'a> {
Object(&'a dyn Serialize),
}

impl<'a> Value<'a> {
impl Value<'_> {
#[inline]
pub fn as_str(&self) -> Option<&str> {
match self {
Expand Down
2 changes: 1 addition & 1 deletion src/msgpack/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl SerializeState {
}
}

impl<'a> std::fmt::Debug for ValueRef<'a> {
impl std::fmt::Debug for ValueRef<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ValueRef::String(s) => write!(f, "String({:?})", s),
Expand Down
4 changes: 0 additions & 4 deletions src/presence/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ impl ActivityContext {
true
}

pub fn update_custom_asset(&mut self, asset: Asset) {
self.custom_asset = Some(asset);
}

pub fn get_effective_name(&self) -> Cow<str> {
if let Some(custom) = &self.custom_asset {
if !custom.name.is_empty() {
Expand Down
9 changes: 4 additions & 5 deletions src/session/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use std::collections::HashMap;
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};

Expand All @@ -6,8 +8,6 @@ use crate::presence::types::Activity;
use crate::types::config::PluginConfig;

pub struct Session {
#[allow(dead_code)]
pub id: u32,
pub workspace: Option<String>,
pub timestamp: Option<u64>,
pub last_activity: Option<Activity>,
Expand All @@ -16,9 +16,8 @@ pub struct Session {
}

impl Session {
pub fn new(id: u32) -> Self {
pub fn new() -> Self {
Self {
id,
workspace: None,
timestamp: None,
last_activity: None,
Expand Down Expand Up @@ -94,7 +93,7 @@ pub struct SessionManager {
impl SessionManager {
pub fn create_session(&self, id: u32, client: PipeClient) {
let mut sessions = self.sessions.write().unwrap();
let mut session = Session::new(id);
let mut session = Session::new();
session.set_pipe_client(client);
sessions.insert(id, session);
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Deserialize for Asset {
let name = remove_field!(input, "name", |v| v.take_string());
let icon = remove_field!(input, "icon", |v| v.take_string());
let tooltip = remove_field!(input, "tooltip", |v| v.take_string());
let ty = get_field!(input, "type", |v| v.as_uinteger())
let ty = get_field!(input, "type", |v| v.as_str())
.try_into()
.map_err(|_| "Invalid asset type")?;

Expand Down
28 changes: 7 additions & 21 deletions src/util/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,16 @@ pub enum AssetType {
Vcs,
}

impl AssetType {
#[inline(always)]
pub fn from(value: &str) -> Option<AssetType> {
match value {
"language" => Some(AssetType::Language),
"file_browser" => Some(AssetType::FileBrowser),
"plugin_manager" => Some(AssetType::PluginManager),
"lsp_manager" => Some(AssetType::LspManager),
"vcs" => Some(AssetType::Vcs),
_ => None,
}
}
}

impl TryFrom<u64> for AssetType {
impl TryFrom<&str> for AssetType {
type Error = ();

fn try_from(value: u64) -> Result<Self, Self::Error> {
fn try_from(value: &str) -> Result<Self, ()> {
match value {
0 => Ok(AssetType::Language),
1 => Ok(AssetType::FileBrowser),
2 => Ok(AssetType::PluginManager),
3 => Ok(AssetType::LspManager),
4 => Ok(AssetType::Vcs),
"language" => Ok(AssetType::Language),
"file_browser" => Ok(AssetType::FileBrowser),
"plugin_manager" => Ok(AssetType::PluginManager),
"lsp_manager" => Ok(AssetType::LspManager),
"vcs" => Ok(AssetType::Vcs),
_ => Err(()),
}
}
Expand Down

0 comments on commit b139bfa

Please sign in to comment.