diff --git a/changelog.md b/changelog.md index da6705e334..3be2fce4d7 100644 --- a/changelog.md +++ b/changelog.md @@ -3,7 +3,7 @@ when upgrading from a version of rust-sdl2 to another. ### Next -[PR #1413](https://github.com/Rust-SDL2/rust-sdl2/pull/1413) **BREAKING CHANGE** Replace `From` implementation of `SwapInterval` that could panic with `TryFrom`. +[PR #1413](https://github.com/Rust-SDL2/rust-sdl2/pull/1413) Deprecate `From` implementation of `SwapInterval` that could panic, add `TryFrom`-like inherent function. [PR #1416](https://github.com/Rust-SDL2/rust-sdl2/pull/1416) Apply clippy fixes, fix deprecations and other code quality improvements. diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 30326ce8a0..ca38d4b11e 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -592,10 +592,9 @@ pub enum SwapInterval { LateSwapTearing = -1, } -impl TryFrom for SwapInterval { - type Error = SwapIntervalConversionError; - - fn try_from(value: i32) -> Result { +impl SwapInterval { + /// This function will be replaced later with a [`TryFrom`] implementation + pub fn try_from(value: i32) -> Result { Ok(match value { -1 => SwapInterval::LateSwapTearing, 0 => SwapInterval::Immediate, @@ -620,6 +619,17 @@ impl fmt::Display for SwapIntervalConversionError { impl Error for SwapIntervalConversionError {} +impl From for SwapInterval { + /// This function is deprecated, use [`SwapInterval::try_from`] instead and handle the error. + fn from(i: i32) -> Self { + println!( + "SwapInterval::from is deprecated (could be called from .into()), \ + use SwapInterval::try_from instead and handle the error" + ); + Self::try_from(i).unwrap() + } +} + /// Represents orientation of a display. #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] #[repr(i32)]