musikr: reformat
This commit is contained in:
parent
b45e41bc3b
commit
c8d645c282
14 changed files with 128 additions and 105 deletions
|
@ -47,7 +47,7 @@ fn main() {
|
|||
} else {
|
||||
panic!("Unsupported Android target: {}", target);
|
||||
};
|
||||
|
||||
|
||||
let clang_path = env::var("CLANG_PATH").expect("CLANG_PATH env var not set");
|
||||
let toolchains_marker = "/toolchains";
|
||||
let ndk_path = if let Some(pos) = clang_path.find(toolchains_marker) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::taglib::iostream::IOStream;
|
||||
use crate::SharedEnv;
|
||||
use jni::objects::{JObject, JValue};
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use crate::SharedEnv;
|
||||
|
||||
pub struct JInputStream<'local> {
|
||||
env: SharedEnv<'local>,
|
||||
|
@ -9,10 +9,7 @@ pub struct JInputStream<'local> {
|
|||
}
|
||||
|
||||
impl<'local, 'a> JInputStream<'local> {
|
||||
pub fn new(
|
||||
env: SharedEnv<'local>,
|
||||
input: JObject<'local>,
|
||||
) -> Self {
|
||||
pub fn new(env: SharedEnv<'local>, input: JObject<'local>) -> Self {
|
||||
Self { env, input }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use jni::objects::{JClass, JObject};
|
||||
use jni::sys::jstring;
|
||||
use jni::JNIEnv;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
mod taglib;
|
||||
mod jstream;
|
||||
mod taglib;
|
||||
|
||||
use taglib::file_ref::FileRef;
|
||||
use jstream::JInputStream;
|
||||
use taglib::file_ref::FileRef;
|
||||
|
||||
type SharedEnv<'local> = Rc<RefCell<JNIEnv<'local>>>;
|
||||
|
||||
|
@ -50,8 +50,11 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
|
|||
None
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Return the title
|
||||
let output = shared_env.borrow_mut().new_string("title").expect("Couldn't create string!");
|
||||
let output = shared_env
|
||||
.borrow_mut()
|
||||
.new_string("title")
|
||||
.expect("Couldn't create string!");
|
||||
output.into_raw()
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use super::bridge::CppAudioProperties;
|
|||
use std::pin::Pin;
|
||||
|
||||
pub struct AudioProperties<'file_ref> {
|
||||
this: Pin<&'file_ref CppAudioProperties>
|
||||
this: Pin<&'file_ref CppAudioProperties>,
|
||||
}
|
||||
|
||||
impl<'file_ref> AudioProperties<'file_ref> {
|
||||
|
@ -24,5 +24,5 @@ impl<'file_ref> AudioProperties<'file_ref> {
|
|||
|
||||
pub fn channels(&self) -> i32 {
|
||||
self.this.as_ref().channels()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ mod bridge_impl {
|
|||
#[cxx_name = "sampleRate"]
|
||||
fn sampleRate(self: Pin<&CppAudioProperties>) -> i32;
|
||||
#[cxx_name = "channels"]
|
||||
fn channels(self: Pin<&CppAudioProperties>) -> i32;
|
||||
fn channels(self: Pin<&CppAudioProperties>) -> i32;
|
||||
|
||||
#[namespace = "TagLib::Ogg::Vorbis"]
|
||||
#[cxx_name = "File"]
|
||||
|
@ -105,7 +105,9 @@ mod bridge_impl {
|
|||
#[cxx_name = "PictureList"]
|
||||
type CPPPictureList;
|
||||
#[namespace = "taglib_shim"]
|
||||
fn PictureList_to_vector(list: Pin<&CPPPictureList>) -> UniquePtr<CxxVector<CPPFLACPicturePointer>>;
|
||||
fn PictureList_to_vector(
|
||||
list: Pin<&CPPPictureList>,
|
||||
) -> UniquePtr<CxxVector<CPPFLACPicturePointer>>;
|
||||
|
||||
#[namespace = "taglib_shim"]
|
||||
#[cxx_name = "PicturePointer"]
|
||||
|
@ -136,7 +138,7 @@ mod bridge_impl {
|
|||
#[cxx_name = "XiphComment"]
|
||||
type CPPXiphComment;
|
||||
#[cxx_name = "fieldListMap"]
|
||||
fn fieldListMap(self: Pin<& CPPXiphComment>) -> &CPPFieldListMap;
|
||||
fn fieldListMap(self: Pin<&CPPXiphComment>) -> &CPPFieldListMap;
|
||||
|
||||
#[namespace = "TagLib"]
|
||||
#[cxx_name = "SimplePropertyMap"]
|
||||
|
@ -164,8 +166,10 @@ mod bridge_impl {
|
|||
#[cxx_name = "FrameList"]
|
||||
type CPPID3v2FrameList;
|
||||
#[namespace = "taglib_shim"]
|
||||
fn FrameList_to_vector(list: Pin<&CPPID3v2FrameList>) -> UniquePtr<CxxVector<CPPFramePointer>>;
|
||||
|
||||
fn FrameList_to_vector(
|
||||
list: Pin<&CPPID3v2FrameList>,
|
||||
) -> UniquePtr<CxxVector<CPPFramePointer>>;
|
||||
|
||||
#[namespace = "taglib_shim"]
|
||||
#[cxx_name = "FramePointer"]
|
||||
type CPPFramePointer;
|
||||
|
@ -175,30 +179,41 @@ mod bridge_impl {
|
|||
#[cxx_name = "Frame"]
|
||||
type CPPID3v2Frame;
|
||||
#[namespace = "taglib_shim"]
|
||||
unsafe fn Frame_asTextIdentification(frame: *const CPPID3v2Frame) -> *const CPPID3v2TextIdentificationFrame;
|
||||
unsafe fn Frame_asTextIdentification(
|
||||
frame: *const CPPID3v2Frame,
|
||||
) -> *const CPPID3v2TextIdentificationFrame;
|
||||
#[namespace = "taglib_shim"]
|
||||
unsafe fn Frame_asUserTextIdentification(frame: *const CPPID3v2Frame) -> *const CPPID3v2UserTextIdentificationFrame;
|
||||
unsafe fn Frame_asUserTextIdentification(
|
||||
frame: *const CPPID3v2Frame,
|
||||
) -> *const CPPID3v2UserTextIdentificationFrame;
|
||||
#[namespace = "taglib_shim"]
|
||||
unsafe fn Frame_asAttachedPicture(frame: *const CPPID3v2Frame) -> *const CPPID3v2AttachedPictureFrame;
|
||||
|
||||
unsafe fn Frame_asAttachedPicture(
|
||||
frame: *const CPPID3v2Frame,
|
||||
) -> *const CPPID3v2AttachedPictureFrame;
|
||||
|
||||
#[namespace = "TagLib::ID3v2"]
|
||||
#[cxx_name = "TextIdentificationFrame"]
|
||||
type CPPID3v2TextIdentificationFrame;
|
||||
#[namespace = "taglib_shim"]
|
||||
fn TextIdentificationFrame_fieldList(frame: Pin<&CPPID3v2TextIdentificationFrame>) -> UniquePtr<CPPStringList>;
|
||||
fn TextIdentificationFrame_fieldList(
|
||||
frame: Pin<&CPPID3v2TextIdentificationFrame>,
|
||||
) -> UniquePtr<CPPStringList>;
|
||||
|
||||
#[namespace = "TagLib::ID3v2"]
|
||||
#[cxx_name = "UserTextIdentificationFrame"]
|
||||
type CPPID3v2UserTextIdentificationFrame;
|
||||
#[namespace = "taglib_shim"]
|
||||
fn UserTextIdentificationFrame_fieldList(frame: Pin<&CPPID3v2UserTextIdentificationFrame>) -> UniquePtr<CPPStringList>;
|
||||
fn UserTextIdentificationFrame_fieldList(
|
||||
frame: Pin<&CPPID3v2UserTextIdentificationFrame>,
|
||||
) -> UniquePtr<CPPStringList>;
|
||||
|
||||
#[namespace = "TagLib::ID3v2"]
|
||||
#[cxx_name = "AttachedPictureFrame"]
|
||||
type CPPID3v2AttachedPictureFrame;
|
||||
#[namespace = "taglib_shim"]
|
||||
fn AttachedPictureFrame_picture(frame: Pin<&CPPID3v2AttachedPictureFrame>) -> UniquePtr<CPPByteVector>;
|
||||
fn AttachedPictureFrame_picture(
|
||||
frame: Pin<&CPPID3v2AttachedPictureFrame>,
|
||||
) -> UniquePtr<CPPByteVector>;
|
||||
|
||||
#[namespace = "TagLib"]
|
||||
#[cxx_name = "String"]
|
||||
|
@ -210,8 +225,10 @@ mod bridge_impl {
|
|||
#[cxx_name = "StringList"]
|
||||
type CPPStringList;
|
||||
#[namespace = "taglib_shim"]
|
||||
fn StringList_to_vector(string_list: Pin<&CPPStringList>) -> UniquePtr<CxxVector<CPPString>>;
|
||||
|
||||
fn StringList_to_vector(
|
||||
string_list: Pin<&CPPStringList>,
|
||||
) -> UniquePtr<CxxVector<CPPString>>;
|
||||
|
||||
#[namespace = "TagLib"]
|
||||
#[cxx_name = "ByteVector"]
|
||||
type CPPByteVector;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use std::pin::Pin;
|
||||
use super::bridge::{self, CPPFile, CPPMPEGFile};
|
||||
use super::audioproperties::AudioProperties;
|
||||
use super::bridge::{self, CPPFile, CPPMPEGFile};
|
||||
use super::flac::FLACFile;
|
||||
use super::id3v2::ID3v2Tag;
|
||||
use super::mpeg::MPEGFile;
|
||||
use super::ogg::OpusFile;
|
||||
use super::ogg::VorbisFile;
|
||||
use super::flac::FLACFile;
|
||||
use super::id3v2::ID3v2Tag;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub struct File<'file_ref> {
|
||||
this: Pin<&'file_ref mut CPPFile>
|
||||
this: Pin<&'file_ref mut CPPFile>,
|
||||
}
|
||||
|
||||
impl<'file_ref> File<'file_ref> {
|
||||
|
@ -17,7 +17,7 @@ impl<'file_ref> File<'file_ref> {
|
|||
}
|
||||
|
||||
pub fn audio_properties(&self) -> Option<AudioProperties<'file_ref>> {
|
||||
let props_ptr = self.this.as_ref().audioProperties();
|
||||
let props_ptr = self.this.as_ref().audioProperties();
|
||||
let props_ref = unsafe {
|
||||
// SAFETY:
|
||||
// - This points to a C++ FFI type ensured to be aligned by cxx's codegen.
|
||||
|
@ -47,7 +47,7 @@ impl<'file_ref> File<'file_ref> {
|
|||
// - There are no datapaths that will yield any mutable pointers or references
|
||||
// to this, ensuring that it will not be mutated as per the aliasing rules.
|
||||
opus_file.as_mut()
|
||||
};
|
||||
};
|
||||
let opus_pin = opus_ref.map(|opus| unsafe { Pin::new_unchecked(opus) });
|
||||
opus_pin.map(|opus| OpusFile::new(opus))
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
pub use super::bridge::CPPFLACFile;
|
||||
pub use super::bridge::CPPFLACPicture;
|
||||
pub use super::xiph::XiphComment;
|
||||
use super::bridge::{CPPPictureList, PictureList_to_vector, FLACFile_pictureList, Picture_data};
|
||||
use super::bridge::{CPPPictureList, FLACFile_pictureList, PictureList_to_vector, Picture_data};
|
||||
use super::tk::ByteVector;
|
||||
use std::marker::PhantomData;
|
||||
pub use super::xiph::XiphComment;
|
||||
use cxx::UniquePtr;
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub struct FLACFile<'file_ref> {
|
||||
this: Pin<&'file_ref mut CPPFLACFile>
|
||||
this: Pin<&'file_ref mut CPPFLACFile>,
|
||||
}
|
||||
|
||||
impl<'file_ref> FLACFile<'file_ref> {
|
||||
|
@ -44,7 +44,10 @@ pub struct PictureList<'file_ref> {
|
|||
|
||||
impl<'file_ref> PictureList<'file_ref> {
|
||||
pub(super) fn new(this: UniquePtr<CPPPictureList>) -> Self {
|
||||
Self { _data: PhantomData, this }
|
||||
Self {
|
||||
_data: PhantomData,
|
||||
this,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_vec(&self) -> Vec<Picture<'file_ref>> {
|
||||
|
@ -71,7 +74,7 @@ impl<'file_ref> PictureList<'file_ref> {
|
|||
}
|
||||
|
||||
pub struct Picture<'file_ref> {
|
||||
this: Pin<&'file_ref CPPFLACPicture>
|
||||
this: Pin<&'file_ref CPPFLACPicture>,
|
||||
}
|
||||
|
||||
impl<'file_ref> Picture<'file_ref> {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use super::bridge::{
|
||||
self, CPPID3v2Frame, CPPID3v2TextIdentificationFrame,
|
||||
CPPID3v2UserTextIdentificationFrame, CPPID3v2AttachedPictureFrame, CPPID3v2Tag, CPPID3v2FrameList
|
||||
self, CPPID3v2AttachedPictureFrame, CPPID3v2Frame, CPPID3v2FrameList, CPPID3v2Tag,
|
||||
CPPID3v2TextIdentificationFrame, CPPID3v2UserTextIdentificationFrame,
|
||||
};
|
||||
use super::tk::{ByteVector, StringList};
|
||||
use std::pin::Pin;
|
||||
use std::marker::PhantomData;
|
||||
use cxx::UniquePtr;
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub struct ID3v2Tag<'file_ref> {
|
||||
this: Pin<&'file_ref CPPID3v2Tag>
|
||||
this: Pin<&'file_ref CPPID3v2Tag>,
|
||||
}
|
||||
|
||||
impl<'file_ref> ID3v2Tag<'file_ref> {
|
||||
|
@ -24,28 +24,34 @@ impl<'file_ref> ID3v2Tag<'file_ref> {
|
|||
|
||||
pub struct FrameList<'file_ref> {
|
||||
_data: PhantomData<&'file_ref CPPID3v2FrameList>,
|
||||
this: UniquePtr<CPPID3v2FrameList>
|
||||
this: UniquePtr<CPPID3v2FrameList>,
|
||||
}
|
||||
|
||||
impl<'file_ref> FrameList<'file_ref> {
|
||||
pub(super) fn new(this: UniquePtr<CPPID3v2FrameList>) -> Self {
|
||||
Self { _data: PhantomData, this }
|
||||
Self {
|
||||
_data: PhantomData,
|
||||
this,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_vec(&self) -> Vec<Frame<'file_ref>> {
|
||||
let this = unsafe { Pin::new_unchecked(self.this.as_ref().unwrap()) };
|
||||
let frames = bridge::FrameList_to_vector(this);
|
||||
frames.iter().map(|frame| {
|
||||
let frame_ptr = frame.get();
|
||||
let frame_ref = unsafe { frame_ptr.as_ref().unwrap() };
|
||||
let frame_pin = unsafe { Pin::new_unchecked(frame_ref) };
|
||||
Frame::new(frame_pin)
|
||||
}).collect()
|
||||
frames
|
||||
.iter()
|
||||
.map(|frame| {
|
||||
let frame_ptr = frame.get();
|
||||
let frame_ref = unsafe { frame_ptr.as_ref().unwrap() };
|
||||
let frame_pin = unsafe { Pin::new_unchecked(frame_ref) };
|
||||
Frame::new(frame_pin)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Frame<'file_ref> {
|
||||
this: Pin<&'file_ref CPPID3v2Frame>
|
||||
this: Pin<&'file_ref CPPID3v2Frame>,
|
||||
}
|
||||
|
||||
impl<'file_ref> Frame<'file_ref> {
|
||||
|
@ -54,27 +60,23 @@ impl<'file_ref> Frame<'file_ref> {
|
|||
}
|
||||
|
||||
pub fn as_text_identification(&mut self) -> Option<TextIdentificationFrame<'file_ref>> {
|
||||
let frame = unsafe {
|
||||
bridge::Frame_asTextIdentification(self.this.as_ref().get_ref())
|
||||
};
|
||||
let frame = unsafe { bridge::Frame_asTextIdentification(self.this.as_ref().get_ref()) };
|
||||
let frame_ref = unsafe { frame.as_ref() };
|
||||
let frame_pin = frame_ref.map(|frame| unsafe { Pin::new_unchecked(frame) });
|
||||
frame_pin.map(|frame| TextIdentificationFrame::new(frame))
|
||||
}
|
||||
|
||||
pub fn as_user_text_identification(&mut self) -> Option<UserTextIdentificationFrame<'file_ref>> {
|
||||
let frame = unsafe {
|
||||
bridge::Frame_asUserTextIdentification(self.this.as_ref().get_ref())
|
||||
};
|
||||
pub fn as_user_text_identification(
|
||||
&mut self,
|
||||
) -> Option<UserTextIdentificationFrame<'file_ref>> {
|
||||
let frame = unsafe { bridge::Frame_asUserTextIdentification(self.this.as_ref().get_ref()) };
|
||||
let frame_ref = unsafe { frame.as_ref() };
|
||||
let frame_pin = frame_ref.map(|frame| unsafe { Pin::new_unchecked(frame) });
|
||||
frame_pin.map(|frame| UserTextIdentificationFrame::new(frame))
|
||||
}
|
||||
|
||||
pub fn as_attached_picture(&mut self) -> Option<AttachedPictureFrame<'file_ref>> {
|
||||
let frame = unsafe {
|
||||
bridge::Frame_asAttachedPicture(self.this.as_ref().get_ref())
|
||||
};
|
||||
let frame = unsafe { bridge::Frame_asAttachedPicture(self.this.as_ref().get_ref()) };
|
||||
let frame_ref = unsafe { frame.as_ref() };
|
||||
let frame_pin = frame_ref.map(|frame| unsafe { Pin::new_unchecked(frame) });
|
||||
frame_pin.map(|frame| AttachedPictureFrame::new(frame))
|
||||
|
@ -82,7 +84,7 @@ impl<'file_ref> Frame<'file_ref> {
|
|||
}
|
||||
|
||||
pub struct TextIdentificationFrame<'file_ref> {
|
||||
this: Pin<&'file_ref CPPID3v2TextIdentificationFrame>
|
||||
this: Pin<&'file_ref CPPID3v2TextIdentificationFrame>,
|
||||
}
|
||||
|
||||
impl<'file_ref> TextIdentificationFrame<'file_ref> {
|
||||
|
@ -97,7 +99,7 @@ impl<'file_ref> TextIdentificationFrame<'file_ref> {
|
|||
}
|
||||
|
||||
pub struct UserTextIdentificationFrame<'file_ref> {
|
||||
this: Pin<&'file_ref CPPID3v2UserTextIdentificationFrame>
|
||||
this: Pin<&'file_ref CPPID3v2UserTextIdentificationFrame>,
|
||||
}
|
||||
|
||||
impl<'file_ref> UserTextIdentificationFrame<'file_ref> {
|
||||
|
@ -112,7 +114,7 @@ impl<'file_ref> UserTextIdentificationFrame<'file_ref> {
|
|||
}
|
||||
|
||||
pub struct AttachedPictureFrame<'file_ref> {
|
||||
this: Pin<&'file_ref CPPID3v2AttachedPictureFrame>
|
||||
this: Pin<&'file_ref CPPID3v2AttachedPictureFrame>,
|
||||
}
|
||||
|
||||
impl<'file_ref> AttachedPictureFrame<'file_ref> {
|
||||
|
@ -124,4 +126,4 @@ impl<'file_ref> AttachedPictureFrame<'file_ref> {
|
|||
let picture = bridge::AttachedPictureFrame_picture(self.this.as_ref());
|
||||
ByteVector::new(picture)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,25 @@
|
|||
|
||||
use super::bridge::{self, CPPIOStream};
|
||||
use std::io::{Read, Write, Seek, SeekFrom};
|
||||
use std::pin::Pin;
|
||||
use cxx::UniquePtr;
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::pin::Pin;
|
||||
|
||||
pub trait IOStream : Read + Write + Seek {
|
||||
pub trait IOStream: Read + Write + Seek {
|
||||
fn name(&self) -> String;
|
||||
fn is_readonly(&self) -> bool;
|
||||
}
|
||||
|
||||
|
||||
pub(super) struct BridgedIOStream<'io_stream> {
|
||||
rs_stream: Pin<Box<DynIOStream<'io_stream>>>,
|
||||
cpp_stream: UniquePtr<CPPIOStream>
|
||||
cpp_stream: UniquePtr<CPPIOStream>,
|
||||
}
|
||||
|
||||
impl<'io_stream> BridgedIOStream<'io_stream> {
|
||||
pub fn new<T : IOStream + 'io_stream>(stream: T) -> Self {
|
||||
pub fn new<T: IOStream + 'io_stream>(stream: T) -> Self {
|
||||
let mut rs_stream = Box::pin(DynIOStream(Box::new(stream)));
|
||||
let cpp_stream = bridge::wrap_RsIOStream(rs_stream.as_mut());
|
||||
BridgedIOStream {
|
||||
rs_stream,
|
||||
cpp_stream
|
||||
cpp_stream,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +30,7 @@ impl<'io_stream> BridgedIOStream<'io_stream> {
|
|||
|
||||
impl<'io_stream> Drop for BridgedIOStream<'io_stream> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
unsafe {
|
||||
// CPP stream references the rust stream, so it must be dropped first
|
||||
std::ptr::drop_in_place(&mut self.cpp_stream);
|
||||
std::ptr::drop_in_place(&mut self.rs_stream);
|
||||
|
@ -44,7 +42,6 @@ impl<'io_stream> Drop for BridgedIOStream<'io_stream> {
|
|||
pub(super) struct DynIOStream<'io_stream>(Box<dyn IOStream + 'io_stream>);
|
||||
|
||||
impl<'io_stream> DynIOStream<'io_stream> {
|
||||
|
||||
// Implement the exposed functions for cxx bridge
|
||||
pub fn name(&mut self) -> String {
|
||||
self.0.name()
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
mod bridge;
|
||||
|
||||
pub mod file_ref;
|
||||
pub mod iostream;
|
||||
pub mod file;
|
||||
pub mod audioproperties;
|
||||
pub mod ogg;
|
||||
pub mod file;
|
||||
pub mod file_ref;
|
||||
pub mod flac;
|
||||
pub mod xiph;
|
||||
pub mod mpeg;
|
||||
pub mod tk;
|
||||
pub mod id3v2;
|
||||
pub mod iostream;
|
||||
pub mod mpeg;
|
||||
pub mod ogg;
|
||||
pub mod tk;
|
||||
pub mod xiph;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::pin::Pin;
|
||||
use super::bridge::{self, CPPMPEGFile};
|
||||
use super::id3v2::ID3v2Tag;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub struct MPEGFile<'file_ref> {
|
||||
this: Pin<&'file_ref mut CPPMPEGFile>
|
||||
this: Pin<&'file_ref mut CPPMPEGFile>,
|
||||
}
|
||||
|
||||
impl<'file_ref> MPEGFile<'file_ref> {
|
||||
|
|
|
@ -3,7 +3,7 @@ use super::xiph::XiphComment;
|
|||
use std::pin::Pin;
|
||||
|
||||
pub struct VorbisFile<'file_ref> {
|
||||
this: Pin<&'file_ref mut CPPVorbisFile>
|
||||
this: Pin<&'file_ref mut CPPVorbisFile>,
|
||||
}
|
||||
|
||||
impl<'file_ref> VorbisFile<'file_ref> {
|
||||
|
@ -25,7 +25,7 @@ impl<'file_ref> VorbisFile<'file_ref> {
|
|||
}
|
||||
|
||||
pub struct OpusFile<'file_ref> {
|
||||
this: Pin<&'file_ref mut CPPOpusFile>
|
||||
this: Pin<&'file_ref mut CPPOpusFile>,
|
||||
}
|
||||
|
||||
impl<'file_ref> OpusFile<'file_ref> {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
use super::bridge::{self, CPPByteVector, CPPString, CPPStringList};
|
||||
use cxx::{UniquePtr, memory::UniquePtrTarget};
|
||||
use cxx::{memory::UniquePtrTarget, UniquePtr};
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
use std::{ffi::CStr, string::ToString};
|
||||
|
||||
enum This<'file_ref, T : UniquePtrTarget> {
|
||||
enum This<'file_ref, T: UniquePtrTarget> {
|
||||
Owned {
|
||||
data: PhantomData<&'file_ref T>,
|
||||
this: UniquePtr<T>,
|
||||
},
|
||||
},
|
||||
Ref {
|
||||
this: Pin<&'file_ref T>,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
pub struct String<'file_ref> {
|
||||
|
@ -24,7 +24,6 @@ impl<'file_ref> String<'file_ref> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'file_ref> ToString for String<'file_ref> {
|
||||
fn to_string(&self) -> std::string::String {
|
||||
let c_str = self.this.toCString(true);
|
||||
|
@ -51,11 +50,18 @@ pub struct StringList<'file_ref> {
|
|||
|
||||
impl<'file_ref> StringList<'file_ref> {
|
||||
pub(super) fn owned(this: UniquePtr<CPPStringList>) -> Self {
|
||||
Self { this: This::Owned { data: PhantomData, this } }
|
||||
Self {
|
||||
this: This::Owned {
|
||||
data: PhantomData,
|
||||
this,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reference(this: Pin<&'file_ref CPPStringList>) -> Self {
|
||||
Self { this: This::Ref { this } }
|
||||
Self {
|
||||
this: This::Ref { this },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_vec(&self) -> Vec<std::string::String> {
|
||||
|
@ -67,9 +73,7 @@ impl<'file_ref> StringList<'file_ref> {
|
|||
cxx_values
|
||||
.iter()
|
||||
.map(|value| {
|
||||
let this = unsafe {
|
||||
Pin::new_unchecked(value)
|
||||
};
|
||||
let this = unsafe { Pin::new_unchecked(value) };
|
||||
String::new(this).to_string()
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
pub use super::bridge::CPPXiphComment;
|
||||
pub use super::flac::PictureList;
|
||||
use super::bridge::{CPPFieldListMap, FieldListMap_to_entries, XiphComment_pictureList};
|
||||
pub use super::flac::PictureList;
|
||||
use super::tk;
|
||||
use std::pin::Pin;
|
||||
use std::collections::HashMap;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub struct XiphComment<'file_ref> {
|
||||
this: Pin<&'file_ref mut CPPXiphComment>
|
||||
this: Pin<&'file_ref mut CPPXiphComment>,
|
||||
}
|
||||
|
||||
impl<'file_ref> XiphComment<'file_ref> {
|
||||
|
@ -17,7 +17,7 @@ impl<'file_ref> XiphComment<'file_ref> {
|
|||
pub fn field_list_map<'slf>(&'slf self) -> FieldListMap<'file_ref> {
|
||||
// To call the method we need, we have to get our mut reference down to an immutable
|
||||
// reference. The safe API can do this, but shortens the lifecycle to at most self, even
|
||||
// though the reference really lives as long as file_ref. Sadly, this requires us to transmute
|
||||
// though the reference really lives as long as file_ref. Sadly, this requires us to transmute
|
||||
// to extend the lifecycle back. This new pointer is really unsafe (we now have both a mut
|
||||
// and an immutable reference to the same object), but it's dropped after this call.
|
||||
// The value returned is unable to actually mutate this object, so it's safe.
|
||||
|
|
Loading…
Reference in a new issue