From 884b23c5a530761cfbb0497de302120e9dfbb67e Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Thu, 6 Oct 2022 16:09:53 -0500 Subject: [PATCH] Minor fixes --- src/lib.rs | 16 +++++++++++----- src/main.rs | 7 +++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8d4c229..40546bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,6 +90,7 @@ clippy::module_name_repetitions, clippy::missing_errors_doc )] +#![cfg_attr(docsrs, feature(doc_cfg))] pub mod physics; pub mod vec2; @@ -107,9 +108,6 @@ use sdl2::{ video::{Window, WindowBuildError, WindowContext}, EventPump, IntegerOrSdlError, }; -use std::fs::File; -use std::io::BufReader; -use std::thread; use std::{ cell::Cell, ops::{Deref, DerefMut}, @@ -782,13 +780,21 @@ impl Game { } } +#[cfg(feature = "audio")] +#[cfg_attr(docsrs, doc(cfg(feature = "audio")))] /// Plays an audio file given the path of file and plays it for y seconds /// ```no_run /// # use cat_box::play; /// play("/path/to/song.mp3", 15); /// ``` -#[cfg(feature = "audio")] -pub fn play + std::marker::Send + 'static>(x: P, y: u64) -> thread::JoinHandle<()> { +pub fn play>(path: P, time: u64) -> std::thread::JoinHandle> { + use std::fs::File; + use std::io::BufReader; + use std::thread; + + // bypass the Send + 'static requirement + let p = path.as_ref(); + thread::spawn(move || { let (_stream, stream_handle) = OutputStream::try_default()?; // Load a sound from a file, using a path relative to Cargo.toml diff --git a/src/main.rs b/src/main.rs index 757f848..4980e07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ #![warn(clippy::pedantic)] -use cat_box::{ - draw_text, get_keyboard_state, get_mouse_state, play, Game, Sprite, SpriteCollection, -}; +use cat_box::{draw_text, get_keyboard_state, get_mouse_state, Game, Sprite, SpriteCollection}; use sdl2::keyboard::Scancode; fn main() { @@ -21,7 +19,8 @@ fn main() { coll.push(x); } } - play(String::from("output.mp3"), 120); + #[cfg(feature = "audio")] + cat_box::play("output.mp3", 120); game.run(|ctx| { i = (i + 1) % 255; ctx.set_background_colour(i as u8, 64, 255);