Skip to content

Commit

Permalink
chore: address clippy warnings
Browse files Browse the repository at this point in the history
decahedron1 committed Oct 18, 2024
1 parent 87dc4f2 commit 67d5794
Showing 12 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use ndarray::{Array1, Array2, Axis, Ix2, s};
use ndarray::{Array2, Axis, Ix2};
use ort::{CUDAExecutionProvider, Error, GraphOptimizationLevel, Session};
use tokenizers::Tokenizer;

4 changes: 3 additions & 1 deletion src/execution_providers/openvino.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::CString, os::raw::c_void};
use std::os::raw::c_void;

use crate::{
error::{Error, Result},
@@ -123,6 +123,8 @@ impl ExecutionProvider for OpenVINOExecutionProvider {
fn register(&self, session_builder: &SessionBuilder) -> Result<()> {
#[cfg(any(feature = "load-dynamic", feature = "openvino"))]
{
use std::ffi::CString;

let device_type = self.device_type.as_deref().map(CString::new).transpose()?;
let device_id = self.device_id.as_deref().map(CString::new).transpose()?;
let cache_dir = self.cache_dir.as_deref().map(CString::new).transpose()?;
4 changes: 2 additions & 2 deletions src/memory.rs
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ pub struct AllocatedBlock<'a> {
allocator: &'a Allocator
}

impl<'a> AllocatedBlock<'a> {
impl AllocatedBlock<'_> {
/// Returns a pointer to the allocated memory.
///
/// Note that, depending on the exact allocator used, this may not a pointer to memory accessible by the CPU.
@@ -222,7 +222,7 @@ impl<'a> AllocatedBlock<'a> {
}
}

impl<'a> Drop for AllocatedBlock<'a> {
impl Drop for AllocatedBlock<'_> {
fn drop(&mut self) {
unsafe { self.allocator.free(self.ptr) };
}
2 changes: 1 addition & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ impl<'s> ModelMetadata<'s> {
}
}

impl<'s> Drop for ModelMetadata<'s> {
impl Drop for ModelMetadata<'_> {
fn drop(&mut self) {
ortsys![unsafe ReleaseModelMetadata(self.metadata_ptr.as_ptr())];
}
10 changes: 5 additions & 5 deletions src/operator/kernel.rs
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ pub trait GetKernelAttribute<'s> {
Self: Sized;
}

impl<'s> GetKernelAttribute<'s> for f32 {
impl GetKernelAttribute<'_> for f32 {
fn get_from(info: *mut ort_sys::OrtKernelInfo, name: *const ort_sys::c_char) -> Option<Self>
where
Self: Sized
@@ -107,7 +107,7 @@ impl<'s> GetKernelAttribute<'s> for f32 {
}
}

impl<'s> GetKernelAttribute<'s> for i64 {
impl GetKernelAttribute<'_> for i64 {
fn get_from(info: *mut ort_sys::OrtKernelInfo, name: *const ort_sys::c_char) -> Option<Self>
where
Self: Sized
@@ -118,7 +118,7 @@ impl<'s> GetKernelAttribute<'s> for i64 {
}
}

impl<'s> GetKernelAttribute<'s> for String {
impl GetKernelAttribute<'_> for String {
fn get_from(info: *mut ort_sys::OrtKernelInfo, name: *const ort_sys::c_char) -> Option<Self>
where
Self: Sized
@@ -131,7 +131,7 @@ impl<'s> GetKernelAttribute<'s> for String {
}
}

impl<'s> GetKernelAttribute<'s> for Vec<f32> {
impl GetKernelAttribute<'_> for Vec<f32> {
fn get_from(info: *mut ort_sys::OrtKernelInfo, name: *const ort_sys::c_char) -> Option<Self>
where
Self: Sized
@@ -144,7 +144,7 @@ impl<'s> GetKernelAttribute<'s> for Vec<f32> {
}
}

impl<'s> GetKernelAttribute<'s> for Vec<i64> {
impl GetKernelAttribute<'_> for Vec<i64> {
fn get_from(info: *mut ort_sys::OrtKernelInfo, name: *const ort_sys::c_char) -> Option<Self>
where
Self: Sized
10 changes: 5 additions & 5 deletions src/session/async.rs
Original file line number Diff line number Diff line change
@@ -50,15 +50,15 @@ impl<'r, 's> InferenceFutInner<'r, 's> {
}
}

unsafe impl<'r, 's> Send for InferenceFutInner<'r, 's> {}
unsafe impl<'r, 's> Sync for InferenceFutInner<'r, 's> {}
unsafe impl Send for InferenceFutInner<'_, '_> {}
unsafe impl Sync for InferenceFutInner<'_, '_> {}

pub enum RunOptionsRef<'r, O: SelectedOutputMarker> {
Arc(Arc<RunOptions<O>>),
Ref(&'r RunOptions<O>)
}

impl<'r, O: SelectedOutputMarker> From<&Arc<RunOptions<O>>> for RunOptionsRef<'r, O> {
impl<O: SelectedOutputMarker> From<&Arc<RunOptions<O>>> for RunOptionsRef<'_, O> {
fn from(value: &Arc<RunOptions<O>>) -> Self {
Self::Arc(Arc::clone(value))
}
@@ -70,7 +70,7 @@ impl<'r, O: SelectedOutputMarker> From<&'r RunOptions<O>> for RunOptionsRef<'r,
}
}

impl<'r, O: SelectedOutputMarker> Deref for RunOptionsRef<'r, O> {
impl<O: SelectedOutputMarker> Deref for RunOptionsRef<'_, O> {
type Target = RunOptions<O>;

fn deref(&self) -> &Self::Target {
@@ -113,7 +113,7 @@ impl<'s, 'r, O: SelectedOutputMarker> Future for InferenceFut<'s, 'r, O> {
}
}

impl<'s, 'r, O: SelectedOutputMarker> Drop for InferenceFut<'s, 'r, O> {
impl<O: SelectedOutputMarker> Drop for InferenceFut<'_, '_, O> {
fn drop(&mut self) {
if !self.did_receive {
let _ = self.run_options.terminate();
6 changes: 3 additions & 3 deletions src/session/input.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ pub enum SessionInputValue<'v> {
Owned(Value<DynValueTypeMarker>)
}

impl<'v> Deref for SessionInputValue<'v> {
impl Deref for SessionInputValue<'_> {
type Target = Value;

fn deref(&self) -> &Self::Target {
@@ -30,7 +30,7 @@ impl<'v, T: ValueTypeMarker + ?Sized> From<ValueRef<'v, T>> for SessionInputValu
SessionInputValue::View(value.into_dyn())
}
}
impl<'v, T: ValueTypeMarker + ?Sized> From<Value<T>> for SessionInputValue<'v> {
impl<T: ValueTypeMarker + ?Sized> From<Value<T>> for SessionInputValue<'_> {
fn from(value: Value<T>) -> Self {
SessionInputValue::Owned(value.into_dyn())
}
@@ -61,7 +61,7 @@ impl<'i, 'v> From<&'i [SessionInputValue<'v>]> for SessionInputs<'i, 'v> {
}
}

impl<'i, 'v, const N: usize> From<[SessionInputValue<'v>; N]> for SessionInputs<'i, 'v, N> {
impl<'v, const N: usize> From<[SessionInputValue<'v>; N]> for SessionInputs<'_, 'v, N> {
fn from(val: [SessionInputValue<'v>; N]) -> Self {
SessionInputs::ValueArray(val)
}
2 changes: 1 addition & 1 deletion src/session/mod.rs
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ pub struct InMemorySession<'s> {
phantom: PhantomData<&'s ()>
}

impl<'s> Deref for InMemorySession<'s> {
impl Deref for InMemorySession<'_> {
type Target = Session;
fn deref(&self) -> &Self::Target {
&self.session
14 changes: 7 additions & 7 deletions src/session/output.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ pub struct SessionOutputs<'r, 's> {
backing_ptr: Option<(&'s Allocator, *mut c_void)>
}

unsafe impl<'r, 's> Send for SessionOutputs<'r, 's> {}
unsafe impl Send for SessionOutputs<'_, '_> {}

impl<'r, 's> SessionOutputs<'r, 's> {
pub(crate) fn new(output_names: impl Iterator<Item = &'r str> + Clone, output_values: impl IntoIterator<Item = DynValue>) -> Self {
@@ -66,43 +66,43 @@ impl<'r, 's> SessionOutputs<'r, 's> {
}
}

impl<'r, 's> Drop for SessionOutputs<'r, 's> {
impl Drop for SessionOutputs<'_, '_> {
fn drop(&mut self) {
if let Some((allocator, ptr)) = self.backing_ptr {
unsafe { allocator.free(ptr) };
}
}
}

impl<'r, 's> Deref for SessionOutputs<'r, 's> {
impl<'r> Deref for SessionOutputs<'r, '_> {
type Target = BTreeMap<&'r str, DynValue>;

fn deref(&self) -> &Self::Target {
&self.map
}
}

impl<'r, 's> DerefMut for SessionOutputs<'r, 's> {
impl DerefMut for SessionOutputs<'_, '_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.map
}
}

impl<'r, 's> Index<&str> for SessionOutputs<'r, 's> {
impl Index<&str> for SessionOutputs<'_, '_> {
type Output = DynValue;
fn index(&self, index: &str) -> &Self::Output {
self.map.get(index).expect("no entry found for key")
}
}

impl<'r, 's> Index<String> for SessionOutputs<'r, 's> {
impl Index<String> for SessionOutputs<'_, '_> {
type Output = DynValue;
fn index(&self, index: String) -> &Self::Output {
self.map.get(index.as_str()).expect("no entry found for key")
}
}

impl<'r, 's> Index<usize> for SessionOutputs<'r, 's> {
impl Index<usize> for SessionOutputs<'_, '_> {
type Output = DynValue;
fn index(&self, index: usize) -> &Self::Output {
self.map.get(&self.idxs[index]).expect("no entry found for key")
2 changes: 1 addition & 1 deletion src/tensor/types.rs
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ impl Utf8Data for String {
}
}

impl<'a> Utf8Data for &'a str {
impl Utf8Data for &str {
fn as_utf8_bytes(&self) -> &[u8] {
self.as_bytes()
}
2 changes: 1 addition & 1 deletion src/value/impl_tensor/create.rs
Original file line number Diff line number Diff line change
@@ -422,7 +422,7 @@ impl<T: Clone + 'static, D: Dimension + 'static> IntoValueTensor for Array<T, D>
}

#[cfg(feature = "ndarray")]
impl<'v, T: Clone + 'static, D: Dimension + 'static> IntoValueTensor for ArrayView<'v, T, D> {
impl<T: Clone + 'static, D: Dimension + 'static> IntoValueTensor for ArrayView<'_, T, D> {
type Item = T;

fn ref_parts(&self) -> Result<(Vec<i64>, &[Self::Item])> {
6 changes: 3 additions & 3 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
@@ -277,7 +277,7 @@ impl<'v, Type: ValueTypeMarker + ?Sized> ValueRef<'v, Type> {
}
}

impl<'v, Type: ValueTypeMarker + ?Sized> Deref for ValueRef<'v, Type> {
impl<Type: ValueTypeMarker + ?Sized> Deref for ValueRef<'_, Type> {
type Target = Value<Type>;

fn deref(&self) -> &Self::Target {
@@ -331,15 +331,15 @@ impl<'v, Type: ValueTypeMarker + ?Sized> ValueRefMut<'v, Type> {
}
}

impl<'v, Type: ValueTypeMarker + ?Sized> Deref for ValueRefMut<'v, Type> {
impl<Type: ValueTypeMarker + ?Sized> Deref for ValueRefMut<'_, Type> {
type Target = Value<Type>;

fn deref(&self) -> &Self::Target {
&self.inner
}
}

impl<'v, Type: ValueTypeMarker + ?Sized> DerefMut for ValueRefMut<'v, Type> {
impl<Type: ValueTypeMarker + ?Sized> DerefMut for ValueRefMut<'_, Type> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}

0 comments on commit 67d5794

Please sign in to comment.