Skip to content

Commit 52dd1b3

Browse files
committed
Clippy
Complaints: * items_after_test_module - projection.rs; `mod test` should come last. * unnecessary_fallible_conversions - array_test.rs; TryFrom with Infallible should be replaced with From.
1 parent 684251d commit 52dd1b3

File tree

2 files changed

+50
-48
lines changed

2 files changed

+50
-48
lines changed

godot-core/src/builtin/projection.rs

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,54 @@ pub enum ProjectionEye {
578578
Right = 2,
579579
}
580580

581+
impl std::fmt::Display for Projection {
582+
/// Formats `Projection` to match Godot's string representation.
583+
///
584+
/// Example:
585+
/// ```
586+
/// use godot::prelude::*;
587+
/// let proj = Projection::new([
588+
/// Vector4::new(1.0, 2.5, 1.0, 0.5),
589+
/// Vector4::new(0.0, 1.5, 2.0, 0.5),
590+
/// Vector4::new(0.0, 0.0, 3.0, 2.5),
591+
/// Vector4::new(3.0, 1.0, 4.0, 1.5),
592+
/// ]);
593+
/// const FMT_RESULT: &str = r"
594+
/// 1, 0, 0, 3
595+
/// 2.5, 1.5, 0, 1
596+
/// 1, 2, 3, 4
597+
/// 0.5, 0.5, 2.5, 1.5
598+
/// ";
599+
/// assert_eq!(format!("{}", proj), FMT_RESULT);
600+
/// ```
601+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
602+
write!(
603+
f,
604+
"\n{}, {}, {}, {}\n{}, {}, {}, {}\n{}, {}, {}, {}\n{}, {}, {}, {}\n",
605+
// first row
606+
self.cols[0][Vector4Axis::X],
607+
self.cols[1][Vector4Axis::X],
608+
self.cols[2][Vector4Axis::X],
609+
self.cols[3][Vector4Axis::X],
610+
// second row
611+
self.cols[0][Vector4Axis::Y],
612+
self.cols[1][Vector4Axis::Y],
613+
self.cols[2][Vector4Axis::Y],
614+
self.cols[3][Vector4Axis::Y],
615+
// third row
616+
self.cols[0][Vector4Axis::Z],
617+
self.cols[1][Vector4Axis::Z],
618+
self.cols[2][Vector4Axis::Z],
619+
self.cols[3][Vector4Axis::Z],
620+
// forth row
621+
self.cols[0][Vector4Axis::W],
622+
self.cols[1][Vector4Axis::W],
623+
self.cols[2][Vector4Axis::W],
624+
self.cols[3][Vector4Axis::W],
625+
)
626+
}
627+
}
628+
581629
#[cfg(test)]
582630
mod test {
583631
// TODO(bromeon): reduce code duplication
@@ -1033,51 +1081,3 @@ mod test {
10331081
crate::builtin::test_utils::roundtrip(&projection, expected_json);
10341082
}
10351083
}
1036-
1037-
impl std::fmt::Display for Projection {
1038-
/// Formats `Projection` to match Godot's string representation.
1039-
///
1040-
/// Example:
1041-
/// ```
1042-
/// use godot::prelude::*;
1043-
/// let proj = Projection::new([
1044-
/// Vector4::new(1.0, 2.5, 1.0, 0.5),
1045-
/// Vector4::new(0.0, 1.5, 2.0, 0.5),
1046-
/// Vector4::new(0.0, 0.0, 3.0, 2.5),
1047-
/// Vector4::new(3.0, 1.0, 4.0, 1.5),
1048-
/// ]);
1049-
/// const FMT_RESULT: &str = r"
1050-
/// 1, 0, 0, 3
1051-
/// 2.5, 1.5, 0, 1
1052-
/// 1, 2, 3, 4
1053-
/// 0.5, 0.5, 2.5, 1.5
1054-
/// ";
1055-
/// assert_eq!(format!("{}", proj), FMT_RESULT);
1056-
/// ```
1057-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1058-
write!(
1059-
f,
1060-
"\n{}, {}, {}, {}\n{}, {}, {}, {}\n{}, {}, {}, {}\n{}, {}, {}, {}\n",
1061-
// first row
1062-
self.cols[0][Vector4Axis::X],
1063-
self.cols[1][Vector4Axis::X],
1064-
self.cols[2][Vector4Axis::X],
1065-
self.cols[3][Vector4Axis::X],
1066-
// second row
1067-
self.cols[0][Vector4Axis::Y],
1068-
self.cols[1][Vector4Axis::Y],
1069-
self.cols[2][Vector4Axis::Y],
1070-
self.cols[3][Vector4Axis::Y],
1071-
// third row
1072-
self.cols[0][Vector4Axis::Z],
1073-
self.cols[1][Vector4Axis::Z],
1074-
self.cols[2][Vector4Axis::Z],
1075-
self.cols[3][Vector4Axis::Z],
1076-
// forth row
1077-
self.cols[0][Vector4Axis::W],
1078-
self.cols[1][Vector4Axis::W],
1079-
self.cols[2][Vector4Axis::W],
1080-
self.cols[3][Vector4Axis::W],
1081-
)
1082-
}
1083-
}

itest/rust/src/builtin_tests/containers/array_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ fn array_from_slice() {
7878
#[itest]
7979
fn array_try_into_vec() {
8080
let array = array![1, 2];
81+
82+
#[allow(clippy::unnecessary_fallible_conversions)]
8183
let result = Vec::<i64>::try_from(&array);
8284
assert_eq!(result, Ok(vec![1, 2]));
8385
}

0 commit comments

Comments
 (0)