Skip to content

Commit 5f18060

Browse files
committed
Refactor get_unity_interface to enforce non-optional return types and improve error handling with unwrap and panic.
1 parent 4cbc1f0 commit 5f18060

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl crate::interface::UnityInterfaceID for TesterContextGraphics {
4141
}
4242

4343
extern "system" fn get_renderer() -> UnityGfxRenderer {
44-
unsafe { crate::interface::get_unity_interface::<TesterContextGraphics>().unwrap().renderer() }
44+
unsafe { crate::interface::get_unity_interface::<TesterContextGraphics>().renderer() }
4545
}
4646

4747
extern "system" fn register_device_event_callback(_: IUnityGraphicsDeviceEventCallback) {}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ pub unsafe fn get_unity_interfaces() -> &'static TesterContextInterfaces {
132132
}
133133
}
134134

135-
pub unsafe fn get_unity_interface<T: UnityInterfaceBase + UnityInterfaceID + 'static>() -> Option<Rc<T>>
135+
pub unsafe fn get_unity_interface<T: UnityInterfaceBase + UnityInterfaceID + 'static>() -> Rc<T>
136136
{
137137
unsafe {
138138
let interface_rc = get_unity_interfaces()
139-
.get_interface(T::get_interface_guid())?;
139+
.get_interface(T::get_interface_guid()).unwrap();
140140

141141
// Rcの中身をダウンキャストして新しいRcを作成
142142
let any_ref = interface_rc.as_any();
143143
if any_ref. is::<T>() {
144144
// unsafeなポインタ操作を使ってRc<T>を作成
145145
let ptr = Rc::as_ptr(&interface_rc) as *const T;
146-
Some(Rc::from_raw(ptr))
146+
Rc::from_raw(ptr)
147147
} else {
148-
None
148+
panic!("interface is not T");
149149
}
150150
}
151151
}

0 commit comments

Comments
 (0)