I am translating several of my Windows programs written in C into rust.There was heavy use of Windows API functions in the programs. As an example, I need to call the CreateWindowExA function. However, since all API functions are considered by Rust to be unsafe, I need to place the function call in a wrapper:
unsafe { hwnd = CreateWindowExA(...); }
But this is burdensome as there are so many API calls in my programs. Is it possible that we declare an external function unsafe in its declaration? For example, can we write something like
pub unsafe fn CreateWindowExA(
dwExStyle: DWORD,
lpClassName: LPCSTR,
lpWindowName: LPCSTR,
dwStyle: DWORD,
x: c_int,
y: c_int,
nWidth: c_int,
nHeight: c_int,
hWndParent: HWND,
hMenu: HMENU,
hInstance: HINSTANCE,
lpParam: LPVOID,
) -> HWND;
I know this is illegal for now, but will Rust adopt it in the future? So that we can get rid of the unsafe wrapper in the caller function body?