musikr: pass iostream ptr to cpp
This commit is contained in:
parent
47604724a4
commit
e22f811c81
4 changed files with 17 additions and 11 deletions
|
@ -11,7 +11,7 @@ namespace taglib_shim
|
|||
class WrappedRsIOStream : public TagLib::IOStream
|
||||
{
|
||||
public:
|
||||
explicit WrappedRsIOStream(rust::Box<RsIOStream> stream);
|
||||
explicit WrappedRsIOStream(RsIOStream *stream);
|
||||
~WrappedRsIOStream() override;
|
||||
|
||||
// TagLib::IOStream interface implementation
|
||||
|
@ -29,10 +29,10 @@ namespace taglib_shim
|
|||
bool isOpen() const override;
|
||||
|
||||
private:
|
||||
rust::Box<RsIOStream> rust_stream;
|
||||
RsIOStream *rust_stream;
|
||||
};
|
||||
|
||||
WrappedRsIOStream::WrappedRsIOStream(rust::Box<RsIOStream> stream) : rust_stream(std::move(stream)) {}
|
||||
WrappedRsIOStream::WrappedRsIOStream(RsIOStream *stream) : rust_stream(stream) {}
|
||||
|
||||
WrappedRsIOStream::~WrappedRsIOStream() = default;
|
||||
|
||||
|
@ -154,9 +154,9 @@ namespace taglib_shim
|
|||
}
|
||||
|
||||
// Factory function to create a new RustIOStream
|
||||
std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(rust::Box<RsIOStream> stream)
|
||||
std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(RsIOStream *stream)
|
||||
{
|
||||
return std::unique_ptr<TagLib::IOStream>(new WrappedRsIOStream(std::move(stream)));
|
||||
return std::unique_ptr<TagLib::IOStream>(new WrappedRsIOStream(stream));
|
||||
}
|
||||
|
||||
} // namespace taglib_shim
|
|
@ -12,5 +12,5 @@ struct RsIOStream;
|
|||
namespace taglib_shim
|
||||
{
|
||||
// Factory functions with external linkage
|
||||
std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(rust::Box<RsIOStream> stream);
|
||||
std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(RsIOStream *stream);
|
||||
} // namespace taglib_shim
|
|
@ -51,8 +51,8 @@ mod bridge_impl {
|
|||
#[namespace = "TagLib"]
|
||||
#[cxx_name = "IOStream"]
|
||||
type CPPIOStream<'io_stream>;
|
||||
fn wrap_RsIOStream<'io_stream>(
|
||||
stream: Box<DynIOStream<'io_stream>>,
|
||||
unsafe fn wrap_RsIOStream<'io_stream>(
|
||||
stream: *mut DynIOStream<'io_stream>,
|
||||
) -> UniquePtr<CPPIOStream<'io_stream>>;
|
||||
|
||||
#[namespace = "TagLib"]
|
||||
|
|
|
@ -14,14 +14,20 @@ pub trait IOStream {
|
|||
}
|
||||
|
||||
pub(super) struct BridgedIOStream<'io_stream> {
|
||||
stream: Box<DynIOStream<'io_stream>>,
|
||||
cpp_stream: UniquePtr<CPPIOStream<'io_stream>>,
|
||||
}
|
||||
|
||||
impl<'io_stream> BridgedIOStream<'io_stream> {
|
||||
pub fn new<T: IOStream + 'io_stream>(stream: T) -> Self {
|
||||
let rs_stream: Box<DynIOStream<'io_stream>> = Box::new(DynIOStream(Box::new(stream)));
|
||||
let cpp_stream: UniquePtr<CPPIOStream<'io_stream>> = bridge::wrap_RsIOStream(rs_stream);
|
||||
BridgedIOStream { cpp_stream }
|
||||
let mut rs_stream: Box<DynIOStream<'io_stream>> = Box::new(DynIOStream(Box::new(stream)));
|
||||
let cpp_stream: UniquePtr<CPPIOStream<'io_stream>> = unsafe {
|
||||
bridge::wrap_RsIOStream(rs_stream.as_mut() as *mut _)
|
||||
};
|
||||
BridgedIOStream {
|
||||
stream: rs_stream,
|
||||
cpp_stream,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cpp_stream(&self) -> &UniquePtr<CPPIOStream> {
|
||||
|
|
Loading…
Reference in a new issue