From 79fe5e180412b860484562ae7fbf79c3dbf4bedd Mon Sep 17 00:00:00 2001 From: Joey Bar Date: Mon, 9 Dec 2024 16:44:37 +0200 Subject: [PATCH] Remove unsafe from some vision framework functions --- Vision/VNObservation.rs | 6 +++--- Vision/VNRecognizeTextRequest.rs | 34 ++++++++++++++++++++------------ Vision/VNRequestHandler.rs | 4 ++-- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Vision/VNObservation.rs b/Vision/VNObservation.rs index cbb913f24..f4984bf1f 100644 --- a/Vision/VNObservation.rs +++ b/Vision/VNObservation.rs @@ -628,11 +628,11 @@ unsafe impl VNRequestRevisionProviding for VNRecognizedText {} extern_methods!( unsafe impl VNRecognizedText { #[method_id(@__retain_semantics Other string)] - pub unsafe fn string(&self) -> Retained; + pub fn string(&self) -> Retained; #[cfg(feature = "VNTypes")] #[method(confidence)] - pub unsafe fn confidence(&self) -> VNConfidence; + pub fn confidence(&self) -> VNConfidence; #[method_id(@__retain_semantics Other boundingBoxForRange:error:_)] pub unsafe fn boundingBoxForRange_error( @@ -683,7 +683,7 @@ unsafe impl VNRequestRevisionProviding for VNRecognizedTextObservation {} extern_methods!( unsafe impl VNRecognizedTextObservation { #[method_id(@__retain_semantics Other topCandidates:)] - pub unsafe fn topCandidates( + pub fn topCandidates( &self, max_candidate_count: NSUInteger, ) -> Retained>; diff --git a/Vision/VNRecognizeTextRequest.rs b/Vision/VNRecognizeTextRequest.rs index 7ecfebfe5..03abba70b 100644 --- a/Vision/VNRecognizeTextRequest.rs +++ b/Vision/VNRecognizeTextRequest.rs @@ -66,41 +66,41 @@ extern_methods!( pub unsafe fn recognitionLanguages(&self) -> Retained>; #[method(setRecognitionLanguages:)] - pub unsafe fn setRecognitionLanguages(&self, recognition_languages: &NSArray); + pub fn setRecognitionLanguages(&self, recognition_languages: &NSArray); #[method_id(@__retain_semantics Other customWords)] - pub unsafe fn customWords(&self) -> Retained>; + pub fn customWords(&self) -> Retained>; #[method(setCustomWords:)] - pub unsafe fn setCustomWords(&self, custom_words: &NSArray); + pub fn setCustomWords(&self, custom_words: &NSArray); #[method(recognitionLevel)] - pub unsafe fn recognitionLevel(&self) -> VNRequestTextRecognitionLevel; + pub fn recognitionLevel(&self) -> VNRequestTextRecognitionLevel; #[method(setRecognitionLevel:)] - pub unsafe fn setRecognitionLevel(&self, recognition_level: VNRequestTextRecognitionLevel); + pub fn setRecognitionLevel(&self, recognition_level: VNRequestTextRecognitionLevel); #[method(usesLanguageCorrection)] - pub unsafe fn usesLanguageCorrection(&self) -> bool; + pub fn usesLanguageCorrection(&self) -> bool; #[method(setUsesLanguageCorrection:)] - pub unsafe fn setUsesLanguageCorrection(&self, uses_language_correction: bool); + pub fn setUsesLanguageCorrection(&self, uses_language_correction: bool); #[method(automaticallyDetectsLanguage)] - pub unsafe fn automaticallyDetectsLanguage(&self) -> bool; + pub fn automaticallyDetectsLanguage(&self) -> bool; #[method(setAutomaticallyDetectsLanguage:)] - pub unsafe fn setAutomaticallyDetectsLanguage(&self, automatically_detects_language: bool); + pub fn setAutomaticallyDetectsLanguage(&self, automatically_detects_language: bool); #[method(minimumTextHeight)] - pub unsafe fn minimumTextHeight(&self) -> c_float; + pub fn minimumTextHeight(&self) -> c_float; #[method(setMinimumTextHeight:)] - pub unsafe fn setMinimumTextHeight(&self, minimum_text_height: c_float); + pub fn setMinimumTextHeight(&self, minimum_text_height: c_float); #[cfg(feature = "VNObservation")] #[method_id(@__retain_semantics Other results)] - pub unsafe fn results(&self) -> Option>>; + pub fn results(&self) -> Option>>; } ); @@ -125,10 +125,18 @@ extern_methods!( #[cfg(feature = "VNRequest")] unsafe impl VNRecognizeTextRequest { #[method_id(@__retain_semantics New new)] - pub unsafe fn new() -> Retained; + pub fn new() -> Retained; } ); +#[cfg(feature = "VNRequest")] +impl DefaultRetained for VNRecognizeTextRequest { + #[inline] + fn default_retained() -> Retained { + Self::new() + } +} + /// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision1?language=objc) pub static VNRecognizeTextRequestRevision1: NSUInteger = 1; diff --git a/Vision/VNRequestHandler.rs b/Vision/VNRequestHandler.rs index acfcb6f61..a4afc4a8c 100644 --- a/Vision/VNRequestHandler.rs +++ b/Vision/VNRequestHandler.rs @@ -56,7 +56,7 @@ extern_methods!( ) -> Retained; #[method_id(@__retain_semantics Init initWithData:options:)] - pub unsafe fn initWithData_options( + pub fn initWithData_options( this: Allocated, image_data: &NSData, options: &NSDictionary, @@ -64,7 +64,7 @@ extern_methods!( #[cfg(feature = "VNRequest")] #[method(performRequests:error:_)] - pub unsafe fn performRequests_error( + pub fn performRequests_error( &self, requests: &NSArray, ) -> Result<(), Retained>;