Skip to content

Commit dba99f0

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 51451e4 commit dba99f0

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

changelog.md

+1-1
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

+14-4
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,9 @@ pub enum SwapInterval {
591591
LateSwapTearing = -1,
592592
}
593593

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

620619
impl Error for SwapIntervalConversionError {}
621620

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

0 commit comments

Comments
 (0)