Skip to content

Commit

Permalink
Fix instances of clippy::missing_panics_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 24, 2024
1 parent 1e6eb56 commit 8380032
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/audio/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ pub fn is_available() -> bool {
///
/// This function returns the name of the default audio capture device.
/// If none is available, an empty string is returned.
///
/// # Panics
///
/// Panics on allocation failure.
#[must_use]
pub fn default_device() -> FBox<CppString> {
unsafe {
Expand All @@ -383,6 +387,10 @@ pub fn default_device() -> FBox<CppString> {
///
/// This function returns a vector of strings, containing the names of all available
/// audio capture devices.
///
/// # Panics
///
/// Panics on allocation failure.
#[must_use]
pub fn available_devices() -> FBox<CppVector<CppString>> {
unsafe {
Expand Down
4 changes: 4 additions & 0 deletions src/audio/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ pub struct Sound<'buf> {
/// Creation
impl<'buf> Sound<'buf> {
/// Create a new `Sound`
///
/// # Panics
///
/// Panics on allocation failure
#[must_use]
pub fn new() -> Self {
let s = unsafe { ffi::audio::sfSound_new() };
Expand Down
4 changes: 3 additions & 1 deletion src/audio/sound_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ impl SoundBuffer {

/// Get the samples stored in the buffer
///
/// Panic if the sample count exceeds usize range
/// # Panics
///
/// Panics if the sample count exceeds usize range
#[must_use]
pub fn samples(&self) -> &[i16] {
let len: usize = self
Expand Down
4 changes: 4 additions & 0 deletions src/audio/sound_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ unsafe extern "C" fn seek_callback<S: SoundStream>(

impl<'a, S: SoundStream> SoundStreamPlayer<'a, S> {
/// Create a new `SoundStreamPlayer` with the specified [`SoundStream`].
///
/// # Panics
///
/// Panics if for some reason a `SoundStreamPlayer` can't be created.
pub fn new(sound_stream: &'a mut S) -> Self {
let channel_count = sound_stream.channel_count();
let sample_rate = sound_stream.sample_rate();
Expand Down
8 changes: 8 additions & 0 deletions src/graphics/convex_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl<'s> ConvexShape<'s> {
///
/// # Arguments
/// * `points_count` - The number of point for the convex shape
///
/// # Panics
///
/// Panics if for some reason a `ConvexShape` can't be created.
#[must_use]
pub fn new(points_count: usize) -> ConvexShape<'s> {
let shape = unsafe { ffi::sfConvexShape_new() };
Expand Down Expand Up @@ -64,6 +68,10 @@ impl<'s> ConvexShape<'s> {
/// # Arguments
/// * index - Index of the point to change, in range `[0 .. get_point_count() - 1]`
/// * point - New position of the point
///
/// # Panics
///
/// Panics on out of bounds access
pub fn set_point<P: Into<Vector2f>>(&mut self, index: usize, point: P) {
assert!(
index < self.point_count(),
Expand Down
4 changes: 4 additions & 0 deletions src/graphics/custom_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ impl<'s> CustomShape<'s> {
///
/// # Arguments
/// * points - Implementation of [`CustomShapePoints`]
///
/// # Panics
///
/// Panics if for some reason a `CustomShape` can't be created.
#[must_use]
pub fn new(points: Box<dyn CustomShapePoints + Send>) -> CustomShape<'s> {
// SAFETY: Box::into_raw produces non-null pointer
Expand Down
9 changes: 4 additions & 5 deletions src/graphics/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,10 @@ impl Font {
/// * `character_size` - Character size, in pixels
#[must_use]
pub fn texture(&self, character_size: u32) -> &Texture {
unsafe {
ffi::sfFont_getTexture(self, character_size)
.as_ref()
.expect("sfFont_getTexture failed")
}
// # Safety
//
// `getTexture` returns a reference, which is never null or dangling.
unsafe { &*ffi::sfFont_getTexture(self, character_size) }
}

/// Tell whether the smooth filter is enabled or not.
Expand Down
8 changes: 8 additions & 0 deletions src/graphics/rc_sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct RcSprite {

impl RcSprite {
/// Create a new sprite
///
/// # Panics
///
/// Panics if for some reason a `Sprite` can't be created.
#[must_use]
pub fn new() -> Self {
let sp = unsafe { ffi::sfSprite_new() };
Expand Down Expand Up @@ -87,6 +91,10 @@ impl RcSprite {
/// * `texture` - New texture
/// * `reset_rect` - Should the texture rect be reset to the size
/// of the new texture?
///
/// # Panics
///
/// Panics on [`std::rc::Rc`] related shenanigans.
pub fn set_texture(&mut self, texture: &RcTexture, reset_rect: bool) {
self.set_rc_texture(texture);
#[expect(clippy::unwrap_used)]
Expand Down
4 changes: 4 additions & 0 deletions src/graphics/rc_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl RcText {
/// Set the font of the `RcText`
///
/// font - New [`RcFont`]
///
/// # Panics
///
/// Panics on [`std::rc::Rc`] related shenanigans.
pub fn set_font(&mut self, font: &RcFont) {
self.set_rc_font(font);
unsafe {
Expand Down
4 changes: 4 additions & 0 deletions src/graphics/rectangle_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub struct RectangleShape<'s> {

impl<'s> RectangleShape<'s> {
/// Returns a new `RectangleShape`.
///
/// # Panics
///
/// Panics if a `RectangleShape` can't be created for some reason.
#[must_use]
pub fn new() -> RectangleShape<'s> {
let rectangle = unsafe { ffi::sfRectangleShape_new() };
Expand Down
9 changes: 4 additions & 5 deletions src/graphics/render_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ impl RenderTexture {
/// Return the target texture
#[must_use]
pub fn texture(&self) -> &Texture {
unsafe {
ffi::sfRenderTexture_getTexture(self)
.as_ref()
.expect("sfRenderTexture_getTexture failed")
}
// # Safety
//
// `getTexture` returns a reference, which is never null or dangling
unsafe { &*ffi::sfRenderTexture_getTexture(self) }
}

/// Enable or disable the smooth filter on a render texture
Expand Down
4 changes: 4 additions & 0 deletions src/graphics/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub struct Sprite<'s> {

impl<'s> Sprite<'s> {
/// Create a new sprite
///
/// # Panics
///
/// Panics if a new `Sprite` can't be created for some reason.
#[must_use]
pub fn new() -> Sprite<'s> {
let sp = unsafe { ffi::sfSprite_new() };
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Texture {

/// Convenience method to easily create and load a `Texture` from a file.
pub fn from_file(filename: &str) -> SfResult<FBox<Self>> {
let mut new = Self::new().expect("Failed to create texture");
let mut new = Self::new()?;
new.load_from_file(filename, IntRect::default())?;
Ok(new)
}
Expand Down
4 changes: 4 additions & 0 deletions src/system/input_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ pub struct InputStream<'src, T> {

impl<'src, T: Read + Seek> InputStream<'src, T> {
/// Create a new input stream from a `Read + Seek` source.
///
/// # Panics
///
/// Panics if a new `InputStream` can't be created for some reason.
pub fn new(stream: &'src mut T) -> InputStream<'src, T> {
let user_data: *mut T = stream;
unsafe {
Expand Down
2 changes: 2 additions & 0 deletions src/system/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ impl SfStr {
}
/// Convert to a UTF-8 `String` from the Rust standard library.
///
/// # Panics
///
/// Panics if the string is not valid UTF-32.
#[must_use]
#[expect(clippy::unwrap_used)]
Expand Down
4 changes: 4 additions & 0 deletions src/window/joystick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ decl_opaque! {
}

/// Get the joystick information.
///
/// # Panics
///
/// Panics if an `Identification` can't be created for some reason
#[must_use]
pub fn identification(joystick: u32) -> FBox<Identification> {
unsafe {
Expand Down

0 comments on commit 8380032

Please sign in to comment.