Skip to content

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Jun 9, 2024
1 parent 0453589 commit 99eb0ea
Show file tree
Hide file tree
Showing 31 changed files with 65 additions and 120 deletions.
56 changes: 3 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ serde_repr = "0.1.16"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
rand = "0.8.5"
atty = "0.2.14"
xkbcommon = { version = "0.7.0", default-features = false, optional = true }
ctrlc = "3.4.1"
libc = "0.2.148"
input-event-codes = "6.2.0"
nix = "0.29.0"
Expand Down
14 changes: 7 additions & 7 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn generate_member(member: &Member) -> TokenStream {
let return_type = member
.return_type
.as_ref()
.map(|r| generate_argument_type(&r, false, true))
.map(|r| generate_argument_type(r, false, true))
.unwrap_or_else(|| quote!(()));

match (side, _type) {
Expand Down Expand Up @@ -496,8 +496,8 @@ fn argument_type_option_name(argument_type: &ArgumentType) -> String {
ArgumentType::Color => "Color".to_string(),
ArgumentType::String => "String".to_string(),
ArgumentType::Bytes => "Bytes".to_string(),
ArgumentType::Vec(v) => format!("{}Vector", argument_type_option_name(&v)),
ArgumentType::Map(m) => format!("{}Map", argument_type_option_name(&m)),
ArgumentType::Vec(v) => format!("{}Vector", argument_type_option_name(v)),
ArgumentType::Map(m) => format!("{}Map", argument_type_option_name(m)),
ArgumentType::NodeID => "Node ID".to_string(),
ArgumentType::Datamap => "Datamap".to_string(),
ArgumentType::ResourceID => "ResourceID".to_string(),
Expand All @@ -519,11 +519,11 @@ fn generate_argument_type(
ArgumentType::UInt => quote!(u32),
ArgumentType::Float => quote!(f32),
ArgumentType::Vec2(t) => {
let t = generate_argument_type(&t, false, true);
let t = generate_argument_type(t, false, true);
quote!(stardust_xr::values::Vector2<#t>)
}
ArgumentType::Vec3(t) => {
let t = generate_argument_type(&t, false, true);
let t = generate_argument_type(t, false, true);
quote!(stardust_xr::values::Vector3<#t>)
}
ArgumentType::Quat => quote!(stardust_xr::values::Quaternion),
Expand All @@ -544,15 +544,15 @@ fn generate_argument_type(
}
}
ArgumentType::Vec(t) => {
let t = generate_argument_type(&t, false, true);
let t = generate_argument_type(t, false, true);
if !owned {
quote!(&[#t])
} else {
quote!(Vec<#t>)
}
}
ArgumentType::Map(t) => {
let t = generate_argument_type(&t, false, true);
let t = generate_argument_type(t, false, true);

if !owned {
quote!(&stardust_xr::values::Map<String, #t>)
Expand Down
14 changes: 4 additions & 10 deletions src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,8 @@ impl Client {
let client = client.clone();
async move {
loop {
match messenger_rx.dispatch(&*scenegraph).await {
Err(e) => {
client.disconnect(Err(e.into()));
}
_ => (),
if let Err(e) = messenger_rx.dispatch(&*scenegraph).await {
client.disconnect(Err(e.into()));
}
}
}
Expand All @@ -160,11 +157,8 @@ impl Client {
let client = client.clone();
async move {
loop {
match messenger_tx.flush().await {
Err(e) => {
client.disconnect(Err(e.into()));
}
_ => (),
if let Err(e) = messenger_tx.flush().await {
client.disconnect(Err(e.into()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl ClientStateParsed {
let file_string = std::fs::read_to_string(file).ok()?;
toml::from_str(&file_string).ok()
}
pub fn to_file(self, directory: &Path) {
pub fn to_file(&self, directory: &Path) {
let app_name = self
.launch_info
.as_ref()
.map(|l| l.cmdline.get(0).unwrap().split('/').last().unwrap())
.map(|l| l.cmdline.first().unwrap().split('/').last().unwrap())
.unwrap_or("unknown");
let state_file_path = directory
.join(format!("{app_name}-{}", nanoid::nanoid!()))
Expand Down
6 changes: 4 additions & 2 deletions src/core/destroy_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use parking_lot::Mutex;
use std::any::Any;
use tokio::sync::mpsc::{self, unbounded_channel};

type Anything = Box<dyn Any + Send + Sync>;

static MAIN_DESTROY_QUEUE: Lazy<(
mpsc::UnboundedSender<Box<dyn Any + Send + Sync>>,
Mutex<mpsc::UnboundedReceiver<Box<dyn Any + Send + Sync>>>,
mpsc::UnboundedSender<Anything>,
Mutex<mpsc::UnboundedReceiver<Anything>>,
)> = Lazy::new(|| {
let (tx, rx) = unbounded_channel();
(tx, Mutex::new(rx))
Expand Down
6 changes: 3 additions & 3 deletions src/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl<T: Send + Sync + ?Sized> Registry<T> {
}
fn lock(&self) -> MappedMutexGuard<FxHashMap<usize, Weak<T>>> {
MutexGuard::map(self.0.lock(), |r| {
r.get_or_insert_with(|| FxHashMap::default())
r.get_or_insert_with(FxHashMap::default)
})
}
pub fn add(&self, t: T) -> Arc<T>
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<T: Send + Sync + ?Sized> Registry<T> {
.collect()
}
pub fn set(&self, other: &Registry<T>) {
*self.lock() = other.lock().clone();
self.lock().clone_from(&other.lock());
}
pub fn take_valid_contents(&self) -> Vec<Arc<T>> {
self.0
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<T: Send + Sync + ?Sized> OwnedRegistry<T> {
}
fn lock(&self) -> MappedMutexGuard<FxHashMap<usize, Arc<T>>> {
MutexGuard::map(self.0.lock(), |r| {
r.get_or_insert_with(|| FxHashMap::default())
r.get_or_insert_with(FxHashMap::default)
})
}
pub fn add(&self, t: T) -> Arc<T>
Expand Down
9 changes: 6 additions & 3 deletions src/core/resource.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use stardust_xr::values::ResourceID;
use std::{ffi::OsStr, path::PathBuf};
use std::{
ffi::OsStr,
path::{Path, PathBuf},
};

use super::client::Client;

lazy_static::lazy_static! {
static ref THEMES: Vec<PathBuf> = std::env::var("STARDUST_THEMES").map(|s| s.split(":").map(PathBuf::from).collect()).unwrap_or_default();
static ref THEMES: Vec<PathBuf> = std::env::var("STARDUST_THEMES").map(|s| s.split(':').map(PathBuf::from).collect()).unwrap_or_default();
}

fn has_extension(path: &PathBuf, extensions: &[&OsStr]) -> bool {
fn has_extension(path: &Path, extensions: &[&OsStr]) -> bool {
if let Some(path_extension) = path.extension() {
extensions.contains(&path_extension)
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/core/scenegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ impl Scenegraph {
}
}

pub struct MethodResponseSender(oneshot::Sender<Result<(Vec<u8>, Vec<OwnedFd>), ScenegraphError>>);
pub type MethodResponse = Result<(Vec<u8>, Vec<OwnedFd>), ScenegraphError>;
pub struct MethodResponseSender(oneshot::Sender<MethodResponse>);
impl MethodResponseSender {
pub fn send(self, t: Result<Message, ScenegraphError>) {
let _ = self.0.send(t.map(|m| (m.data, m.fds)));
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::empty_docs)]
mod core;
mod nodes;
mod objects;
Expand Down Expand Up @@ -399,7 +400,7 @@ fn run_client(
#[cfg(feature = "wayland")]
{
if let Some(wayland_socket) = wayland.socket_name.as_ref() {
command.env("WAYLAND_DISPLAY", &wayland_socket);
command.env("WAYLAND_DISPLAY", wayland_socket);
}
command.env(
"DISPLAY",
Expand Down Expand Up @@ -429,7 +430,7 @@ async fn save_session(project_dirs: &ProjectDirs) {
local_set.spawn_local(async move {
tokio::select! {
biased;
s = client.save_state() => {s.map(|s| s.to_file(&session_dir));},
s = client.save_state() => {if let Some(s) = s { s.to_file(&session_dir) }},
_ = tokio::time::sleep(Duration::from_millis(100)) => (),
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Alias {

fn add_to(new_node: &Arc<Node>, original: &Arc<Node>, info: AliasInfo) -> Result<()> {
let alias = Alias {
node: Arc::downgrade(&new_node),
node: Arc::downgrade(new_node),
original: Arc::downgrade(original),
info,
};
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn mask_matches(mask_map_lesser: &Datamap, mask_map_greater: &Datamap) -> bo
let greater_key = get_mask(mask_map_greater)?.index(key)?;
// otherwise zero-length vectors don't count the same as a single type vector
if lesser_key.flexbuffer_type().is_heterogenous_vector()
&& lesser_key.as_vector().len() == 0
&& lesser_key.as_vector().is_empty()
&& greater_key.flexbuffer_type().is_vector()
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/drawable/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Lines {
thickness: (first.thickness + last.thickness) * 0.5,
color: color.into(),
};
points.push_front(connect_point.clone());
points.push_front(connect_point);
points.push_back(connect_point);
}
stereokit_rust::system::Lines::add_list(token, points.make_contiguous());
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/drawable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ pub fn draw(token: &MainThreadToken) {
text::draw_all(token);

if let Some(skytex) = QUEUED_SKYTEX.lock().take() {
if let Ok(skytex) = SHCubemap::from_cubemap_equirectangular(&skytex, true, 100) {
if let Ok(skytex) = SHCubemap::from_cubemap_equirectangular(skytex, true, 100) {
Renderer::skytex(skytex.tex);
}
}
if let Some(skylight) = QUEUED_SKYLIGHT.lock().take() {
if let Ok(skylight) = SHCubemap::from_cubemap_equirectangular(&skylight, true, 100) {
if let Ok(skylight) = SHCubemap::from_cubemap_equirectangular(skylight, true, 100) {
Renderer::skylight(skylight.sh);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/drawable/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl MaterialParameter {
}
MaterialParameter::Texture(resource) => {
let Some(texture_path) =
get_resource_file(&resource, &client, &[OsStr::new("png"), OsStr::new("jpg")])
get_resource_file(resource, client, &[OsStr::new("png"), OsStr::new("jpg")])
else {
return;
};
Expand Down
5 changes: 2 additions & 3 deletions src/nodes/drawable/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use smithay::backend::renderer::gles::{
ffi::{self, Gles2, FRAGMENT_SHADER, VERTEX_SHADER},
GlesError,
};
use std::mem::transmute;
use stereokit_rust::shader::Shader;
use stereokit_rust::shader::{Shader, _ShaderT};
use tracing::error;

// Simula shader with fancy lanzcos sampling
Expand Down Expand Up @@ -133,7 +132,7 @@ pub unsafe fn shader_inject(
let gl_frag = compile_shader(c, FRAGMENT_SHADER, frag_str)?;
let gl_prog = link_program(c, gl_vert, gl_frag)?;

let shader: *mut FfiShader = transmute(sk_shader.0.as_mut());
let shader = sk_shader.0.as_mut() as *mut _ShaderT as *mut FfiShader;
if let Some(shader) = shader.as_mut() {
shader.shader.vertex = gl_vert;
shader.shader.pixel = gl_frag;
Expand Down
Loading

0 comments on commit 99eb0ea

Please sign in to comment.