From 42dfe4edcc3129ca3c5e5826fb5c359670313cea Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Wed, 12 Feb 2025 19:15:01 -0700 Subject: [PATCH] musikr: reformat --- musikr/src/main/jni/build.rs | 2 +- musikr/src/main/jni/src/jni_stream.rs | 5 +-- musikr/src/main/jni/src/lib.rs | 12 ++++--- musikr/src/main/jni/src/taglib/ffi.rs | 44 ++++++++++++------------ musikr/src/main/jni/src/taglib/stream.rs | 20 +++-------- 5 files changed, 36 insertions(+), 47 deletions(-) diff --git a/musikr/src/main/jni/build.rs b/musikr/src/main/jni/build.rs index 71fce6f68..5c21e10e8 100644 --- a/musikr/src/main/jni/build.rs +++ b/musikr/src/main/jni/build.rs @@ -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) { diff --git a/musikr/src/main/jni/src/jni_stream.rs b/musikr/src/main/jni/src/jni_stream.rs index 5077a2bcb..2d719c1dd 100644 --- a/musikr/src/main/jni/src/jni_stream.rs +++ b/musikr/src/main/jni/src/jni_stream.rs @@ -13,10 +13,7 @@ impl<'local, 'a> JInputStream<'local, 'a> { env: &'a mut JNIEnv<'local>, input: JObject<'local>, ) -> Result { - Ok(JInputStream { - env, - input, - }) + Ok(JInputStream { env, input }) } } diff --git a/musikr/src/main/jni/src/lib.rs b/musikr/src/main/jni/src/lib.rs index f6378b13a..3fc2f7e6e 100644 --- a/musikr/src/main/jni/src/lib.rs +++ b/musikr/src/main/jni/src/lib.rs @@ -2,11 +2,11 @@ use jni::objects::{JClass, JObject}; use jni::sys::jstring; use jni::JNIEnv; -mod taglib; mod jni_stream; +mod taglib; -pub use taglib::*; use jni_stream::JInputStream; +pub use taglib::*; #[no_mangle] pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>( @@ -19,7 +19,9 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>( Ok(stream) => stream, Err(e) => { let error = format!("Failed to create input stream: {}", e); - let error_str = env.new_string(error).expect("Couldn't create error string!"); + let error_str = env + .new_string(error) + .expect("Couldn't create error string!"); return error_str.into_raw(); } }; @@ -29,7 +31,9 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>( Some(file_ref) => file_ref, None => { let error = "Failed to create File"; - let error_str = env.new_string(error).expect("Couldn't create error string!"); + let error_str = env + .new_string(error) + .expect("Couldn't create error string!"); return error_str.into_raw(); } }; diff --git a/musikr/src/main/jni/src/taglib/ffi.rs b/musikr/src/main/jni/src/taglib/ffi.rs index 65a649558..2303ec09b 100644 --- a/musikr/src/main/jni/src/taglib/ffi.rs +++ b/musikr/src/main/jni/src/taglib/ffi.rs @@ -1,7 +1,7 @@ +use std::collections::HashMap; use std::ffi::CStr; use std::pin::Pin; use std::string::ToString; -use std::collections::HashMap; #[cxx::bridge] pub(crate) mod bindings { @@ -148,7 +148,7 @@ impl bindings::FileRef { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The file data is a pointer that does not depend on the // address of self. let this = Pin::new_unchecked(&*self); @@ -179,7 +179,7 @@ impl bindings::BaseFile { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The audio properties data is a pointer that does not depend on the // address of self. let this: Pin<&bindings::BaseFile> = Pin::new_unchecked(self); @@ -195,7 +195,7 @@ impl bindings::BaseFile { props.as_ref() } } - + pub fn as_opus(&self) -> Option<&bindings::OpusFile> { let ptr_self = self as *const Self; let opus_file = unsafe { @@ -243,7 +243,7 @@ impl bindings::AudioProperties { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is copied and thus not dependent on the address of self. let this = Pin::new_unchecked(self); this.thisLengthInMilliseconds() @@ -255,7 +255,7 @@ impl bindings::AudioProperties { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is copied and thus not dependent on the address of self. let this = Pin::new_unchecked(self); this.thisBitrate() @@ -267,7 +267,7 @@ impl bindings::AudioProperties { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is copied and thus not dependent on the address of self. let this = Pin::new_unchecked(self); this.thisSampleRate() @@ -279,7 +279,7 @@ impl bindings::AudioProperties { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is copied and thus not dependent on the address of self. let this = Pin::new_unchecked(self); this.thisChannels() @@ -293,12 +293,12 @@ impl bindings::OpusFile { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is a pointer that does not depend on the address of self. let this = Pin::new_unchecked(self); this.opusThisTag() }; - unsafe { + unsafe { // SAFETY: This pointer is a valid type, and can only used and accessed // via this function and thus cannot be mutated, satisfying the aliasing rules. tag.as_ref() @@ -312,12 +312,12 @@ impl bindings::VorbisFile { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is a pointer that does not depend on the address of self. let this = Pin::new_unchecked(self); this.vorbisThisTag() }; - unsafe { + unsafe { // SAFETY: This pointer is a valid type, and can only used and accessed // via this function and thus cannot be mutated, satisfying the aliasing rules. tag.as_ref() @@ -331,7 +331,7 @@ impl bindings::XiphComment { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is a reference that does not depend on the address of self. let this = Pin::new_unchecked(self); this.thisFieldListMap() @@ -345,7 +345,7 @@ impl bindings::SimplePropertyMap { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value is a unique_ptr to a copied vector that is not dependent // on the address of self. let this = Pin::new_unchecked(self); @@ -361,7 +361,7 @@ impl bindings::Property { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The values returned are copied and thus not dependent on the address // of self. let this = Pin::new_unchecked(self); @@ -377,26 +377,26 @@ impl ToString for bindings::TString { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value returned are pointers and thus not dependent on the address // of self. let this: Pin<&bindings::TString> = Pin::new_unchecked(self); this.thisToCString(true) }; - unsafe { + unsafe { // SAFETY: // - This is a C-string returned by a C++ method guaranteed to have // a null terminator. // - This C-string is fully allocated and owned by the TagString instance, // in a continous block from start to null terminator. // - This C-string will be non-null even if empty. - // - This pointer will not be mutated before it's entirely copied into + // - This pointer will not be mutated before it's entirely copied into // rust. // - This C-string is copied to a rust string before TagString is destroyed. - CStr::from_ptr(c_str) + CStr::from_ptr(c_str) } - .to_string_lossy() - .to_string() + .to_string_lossy() + .to_string() } } @@ -406,7 +406,7 @@ impl bindings::TStringList { // SAFETY: // - This pin is only used in this unsafe scope. // - The pin is used as a C++ this pointer in the ffi call, which does - // not change address by C++ semantics. + // not change address by C++ semantics. // - The value returned is a unique ptr to a copied vector that is not // dependent on the address of self. let this = Pin::new_unchecked(self); diff --git a/musikr/src/main/jni/src/taglib/stream.rs b/musikr/src/main/jni/src/taglib/stream.rs index 80b6b1366..069266c40 100644 --- a/musikr/src/main/jni/src/taglib/stream.rs +++ b/musikr/src/main/jni/src/taglib/stream.rs @@ -28,33 +28,21 @@ pub extern "C" fn rust_stream_name(stream: *mut c_void) -> *const c_char { } #[no_mangle] -pub extern "C" fn rust_stream_read( - stream: *mut c_void, - buffer: *mut u8, - length: usize, -) -> usize { +pub extern "C" fn rust_stream_read(stream: *mut c_void, buffer: *mut u8, length: usize) -> usize { let stream = unsafe { &mut *(stream as *mut RustStream<'_>) }; let buffer = unsafe { std::slice::from_raw_parts_mut(buffer, length) }; stream.0.read(buffer).unwrap_or(0) } #[no_mangle] -pub extern "C" fn rust_stream_write( - stream: *mut c_void, - data: *const u8, - length: usize, -) { +pub extern "C" fn rust_stream_write(stream: *mut c_void, data: *const u8, length: usize) { let stream = unsafe { &mut *(stream as *mut RustStream<'_>) }; let data = unsafe { std::slice::from_raw_parts(data, length) }; stream.0.write_all(data).unwrap(); } #[no_mangle] -pub extern "C" fn rust_stream_seek( - stream: *mut c_void, - offset: i64, - whence: i32, -) { +pub extern "C" fn rust_stream_seek(stream: *mut c_void, offset: i64, whence: i32) { let stream = unsafe { &mut *(stream as *mut RustStream<'_>) }; let pos = match whence { 0 => SeekFrom::Start(offset as u64), @@ -91,4 +79,4 @@ pub extern "C" fn rust_stream_length(stream: *mut c_void) -> i64 { pub extern "C" fn rust_stream_is_readonly(stream: *const c_void) -> bool { let stream = unsafe { &*(stream as *const RustStream<'_>) }; stream.0.is_readonly() -} \ No newline at end of file +}