Comments (3)
Hi, thanks for opening the issue! This sounds reasonable, but I would like to preserve the ability to convert &self
to *mut T
as it's quite convenient in practice in combination with winapi. Therefore this function should be unsafe
as it's not totally safe as you mention. Would that be fine?
Side-note: A bit more mature ComPtr
implementation can be found here (https://github.com/retep998/wio-rs/blob/master/src/com.rs), which is also published on crates.io.
from comptr-rs.
I think it's fine to have an unsafe method which does this. However, it'd be nice to have a safe method which takes &mut self -> *mut T
as well.
The particular place that the current behavior surprised me is for this code:
let mut hardware_adapter = get_hardware_adapter(&mut factory)?;
let result = unsafe {
D3D12CreateDevice(
hardware_adapter.as_mut_ptr() as *mut winapi::IUnknown,
D3D_FEATURE_LEVEL_11_0,
&IID_ID3D12Device,
IID_PPV_ARGS!(&self.device),
)
};
if !SUCCEEDED(result) {
return Err("failed to create D3D12 device");
}
The compiler is warning me that hardware_adapter
does not need to be mutable, however the first argument to D3D12CreateDevice
has type *mut IUnknown
.
Thanks for the link to the other implementation! I'll check it out and see if it works for my use case.
from comptr-rs.
I see, thanks for the writeup.
The closest thing we have atm is as_mut
with the signature &mut self -> &mut *mut T
, which can be derefenced to achieve the desired behavior.
Nonetheless I would be fine with adding a new function but couldn't come up with a reasonable name atm! (or a good new name for as_mut_ptr
).
Also, here our ported code over to wio
from gfx-rs
(d3d12 implementation): https://github.com/gfx-rs/gfx/blob/master/src/backend/dx12/src/lib.rs#L225-L288
from comptr-rs.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comptr-rs.