Skip to content

Commit b2f24d1

Browse files
committed
put From impl back, inform users of deprecation with a doc comment and a println
Notes: - Trait implementations can't be deprecated, so had to use some other way. - try_from is now an inherent function because From and TryFrom can't be implemented at the same time.
1 parent 8d632d5 commit b2f24d1

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ when upgrading from a version of rust-sdl2 to another.
33

44
### Next
55

6-
[PR #1413](https://github.com/Rust-SDL2/rust-sdl2/pull/1413) **BREAKING CHANGE** Replace `From` implementation of `SwapInterval` that could panic with `TryFrom`.
6+
[PR #1413](https://github.com/Rust-SDL2/rust-sdl2/pull/1413) Deprecate `From` implementation of `SwapInterval` that could panic, add `TryFrom`-like inherent function.
77

88
[PR #1416](https://github.com/Rust-SDL2/rust-sdl2/pull/1416) Apply clippy fixes, fix deprecations and other code quality improvements.
99

src/sdl2/video.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,9 @@ pub enum SwapInterval {
592592
LateSwapTearing = -1,
593593
}
594594

595-
impl TryFrom<i32> for SwapInterval {
596-
type Error = SwapIntervalConversionError;
597-
598-
fn try_from(value: i32) -> Result<Self, Self::Error> {
595+
impl SwapInterval {
596+
/// This function will be replaced later with a [`TryFrom`] implementation
597+
pub fn try_from(value: i32) -> Result<Self, SwapIntervalConversionError> {
599598
Ok(match value {
600599
-1 => SwapInterval::LateSwapTearing,
601600
0 => SwapInterval::Immediate,
@@ -620,6 +619,17 @@ impl fmt::Display for SwapIntervalConversionError {
620619

621620
impl Error for SwapIntervalConversionError {}
622621

622+
impl From<i32> for SwapInterval {
623+
/// This function is deprecated, use [`SwapInterval::try_from`] instead and handle the error.
624+
fn from(i: i32) -> Self {
625+
println!(
626+
"SwapInterval::from is deprecated (could be called from .into()), \
627+
use SwapInterval::try_from instead and handle the error"
628+
);
629+
Self::try_from(i).unwrap()
630+
}
631+
}
632+
623633
/// Represents orientation of a display.
624634
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
625635
#[repr(i32)]

0 commit comments

Comments
 (0)