Skip to content

Commit 5e6c9c1

Browse files
committed
Remove redundant unsafe blocks in interface.rs for cleaner and safer code.
1 parent b6cb8ad commit 5e6c9c1

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

unity-native-plugin-tester/src/interface.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@ impl TesterContextInterfaces {
9191
static UNITY_INTERFACES: OnceLock<TesterContextInterfaces> = OnceLock::new();
9292

9393
extern "system" fn get_interface(guid: UnityInterfaceGUID) -> *mut IUnityInterface {
94-
unsafe {
95-
if let Some(i) = UNITY_INTERFACES.get().unwrap().get_interface(guid) {
96-
i.as_ref().get_unity_interface()
97-
} else {
98-
std::ptr::null_mut()
99-
}
94+
if let Some(i) = UNITY_INTERFACES.get().unwrap().get_interface(guid) {
95+
i.as_ref().get_unity_interface()
96+
} else {
97+
std::ptr::null_mut()
10098
}
10199
}
102100

@@ -106,16 +104,14 @@ extern "system" fn get_interface_split(
106104
high: ::std::os::raw::c_ulonglong,
107105
low: ::std::os::raw::c_ulonglong,
108106
) -> *mut IUnityInterface {
109-
unsafe {
110-
if let Some(i) = UNITY_INTERFACES
111-
.get()
112-
.unwrap()
113-
.get_interface_split(high, low)
114-
{
115-
i.as_ref().get_unity_interface()
116-
} else {
117-
std::ptr::null_mut()
118-
}
107+
if let Some(i) = UNITY_INTERFACES
108+
.get()
109+
.unwrap()
110+
.get_interface_split(high, low)
111+
{
112+
i.as_ref().get_unity_interface()
113+
} else {
114+
std::ptr::null_mut()
119115
}
120116
}
121117

@@ -127,9 +123,7 @@ extern "system" fn register_interface_split(
127123
}
128124

129125
pub unsafe fn get_unity_interfaces() -> &'static TesterContextInterfaces {
130-
unsafe {
131-
UNITY_INTERFACES.get().unwrap()
132-
}
126+
UNITY_INTERFACES.get().unwrap()
133127
}
134128

135129
pub unsafe fn get_unity_interface<T: UnityInterfaceBase + UnityInterfaceID + 'static>() -> Rc<T>
@@ -140,7 +134,7 @@ pub unsafe fn get_unity_interface<T: UnityInterfaceBase + UnityInterfaceID + 'st
140134

141135
// Rcの中身をダウンキャストして新しいRcを作成
142136
let any_ref = interface_rc.as_any();
143-
if let Some(concrete_ref) = any_ref.downcast_ref::<T>() {
137+
if let Some(_) = any_ref.downcast_ref::<T>() {
144138
// Use Rc::clone to safely create an Rc<T>
145139
// First, get a raw pointer from the original Rc
146140
let ptr = Rc::as_ptr(&interface_rc);

0 commit comments

Comments
 (0)