Skip to content

Commit

Permalink
Clippy fixes and try to fix dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsik-sus committed Sep 26, 2022
1 parent 793ae39 commit b5db8f7
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 30 deletions.
5 changes: 1 addition & 4 deletions module/rust/time_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ full = [
use_std = []
use_alloc = []

now = [ "use_std", "chrono", "chrono/default" ]
now = [ "use_std" ]

[lib]
name = "time_tools"
Expand All @@ -59,9 +59,6 @@ path = "rust/test/_integration_test/smoke_test.rs"
name = "time_tools_trivial_sample"
path = "sample/rust/time_tools_trivial_sample/src/main.rs"

[dependencies]
chrono = { version = "~0.4", optional = true, default-features = false }

[dev-dependencies]
test_tools = { version = "~0.1", path = "../../rust/test_tools" }

2 changes: 1 addition & 1 deletion rust/impl/dt/interval_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub( crate ) mod private
/// Both [core::ops::Range], [core::ops::RangeInclusive] are convertable to [crate::Interval]
///
#[ derive( PartialEq, Debug ) ]
#[ derive( PartialEq, Eq, Debug ) ]
pub struct Interval< T = isize >
where
T : std::ops::Sub< Output = T > + std::ops::Add< Output = T > + Copy,
Expand Down
1 change: 0 additions & 1 deletion rust/impl/dt/type_constructor/vectorized_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pub( crate ) mod private
{
fn vectorized_from( _ : () ) -> Self
{
()
}
}

Expand Down
5 changes: 4 additions & 1 deletion rust/impl/iter/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ pub mod exposed
rev,
sorted,
unfold,
zip,
// zip,
zip_eq,
};

#[ doc( inline ) ]
pub use std::iter::zip;

}

#[ doc( inline ) ]
Expand Down
18 changes: 13 additions & 5 deletions rust/impl/time/now.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use chrono::prelude::*;
use std::time;

///
/// Get current time. Units are milliseconds.
///
pub fn now() -> i64
{
Utc::now().timestamp_millis()
time::SystemTime::now()
.duration_since( time::UNIX_EPOCH ).unwrap()
.as_millis() as i64
}

///
Expand All @@ -20,7 +22,9 @@ pub mod s
/// Get current time. Units are seconds.
pub fn now() -> i64
{
Utc::now().timestamp()
time::SystemTime::now()
.duration_since( time::UNIX_EPOCH ).unwrap()
.as_secs() as i64
}
}

Expand All @@ -35,7 +39,9 @@ pub mod ms
/// Get current time. Units are milliseconds.
pub fn now() -> i64
{
Utc::now().timestamp_millis()
time::SystemTime::now()
.duration_since( time::UNIX_EPOCH ).unwrap()
.as_millis() as i64
}
}

Expand All @@ -53,6 +59,8 @@ pub mod ns
/// Get current time. Units are nanoseconds.
pub fn now() -> i64
{
Utc::now().timestamp_nanos()
time::SystemTime::now()
.duration_since( time::UNIX_EPOCH ).unwrap()
.as_nanos() as i64
}
}
4 changes: 2 additions & 2 deletions rust/impl/video/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub( crate ) mod private
{

/// Select strategy for the output format.
#[ derive( Debug, PartialEq ) ]
#[ derive( Debug, PartialEq, Eq ) ]
pub enum EncoderType
{
/// Convert to gif.
Expand All @@ -23,7 +23,7 @@ pub( crate ) mod private
}

/// Select color encoding.
#[ derive( Debug, Clone, PartialEq ) ]
#[ derive( Debug, Clone, PartialEq, Eq ) ]
pub enum ColorType
{
/// RGB color encoding.
Expand Down
8 changes: 4 additions & 4 deletions rust/impl/video/encoder_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ pub( crate ) mod private
{
if encoder_type == &EncoderType::Gif
{
let encoder = Gif::new( dims.clone(), frame_rate, repeat, color_type, filename )?;
let encoder = Gif::new( *dims, frame_rate, repeat, color_type, filename )?;
return Ok( Box::new( encoder ) );
}
if encoder_type == &EncoderType::Png
{
let encoder = Png::new( dims.clone(), frame_rate, repeat, color_type, filename )?;
let encoder = Png::new( *dims, frame_rate, repeat, color_type, filename )?;
return Ok( Box::new( encoder ) );
}
if encoder_type == &EncoderType::Mp4
{
let encoder = Mp4::new( dims.clone(), frame_rate, repeat, color_type, filename )?;
let encoder = Mp4::new( *dims, frame_rate, repeat, color_type, filename )?;
return Ok( Box::new( encoder ) );
}

Expand Down Expand Up @@ -145,7 +145,7 @@ pub( crate ) mod private
self.frame_rate,
self.repeat,
&self.color_type,
self.output_filename.to_str().ok_or( BasicError::new( "cannot form filename" ) )?
self.output_filename.to_str().ok_or_else( | | BasicError::new( "cannot form filename" ) )?
)?;
self.encoder = encoder;
Ok( () )
Expand Down
4 changes: 2 additions & 2 deletions rust/impl/video/encoders/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub( crate ) mod private

for image in &self.images_buffer
{
let encoded = encoder.write_frame( &image, frame.clone() );
let encoded = encoder.write_frame( image, frame.clone() );
if encoded.is_err()
{
return Err( Box::new( BasicError::new( "cannot write frame" ) ) );
Expand Down Expand Up @@ -206,7 +206,7 @@ pub( crate ) mod private
{
Some( 0 ) => u32::MAX,
Some( n ) => n as u32,
None => 1 as u32,
None => 1_u32,
};

let instance = Self
Expand Down
12 changes: 4 additions & 8 deletions rust/impl/video/yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ pub( crate ) mod private
pub fn yuv444_to_rgb( buffer : &[ u8 ] ) -> Vec< u8 >
{
buffer.chunks_exact( 3 )
.map(| yuv | yuv_to_rgb( yuv[ 0 ], yuv[ 1 ], yuv[ 2 ] ) )
.flatten()
.flat_map(| yuv | yuv_to_rgb( yuv[ 0 ], yuv[ 1 ], yuv[ 2 ] ) )
.collect()
}

/// Convert one Y'UV422(also known as YUYV or YUY2) frame to RGB888
pub fn yuv422_to_rgb( buffer : &[ u8 ] ) -> Vec< u8 >
{
buffer.chunks_exact( 4 )
.map( | yuv |
.flat_map( | yuv |
[
yuv_to_rgb( yuv[ 0 ], yuv[ 1 ], yuv[ 3 ] ),
yuv_to_rgb( yuv[ 2 ], yuv[ 1 ], yuv[ 3 ] ),
] )
.flatten()
.flatten()
.collect()
}

Expand Down Expand Up @@ -85,14 +83,13 @@ pub( crate ) mod private
{
y_plane.chunks_exact( width * 2 )
.zip( u_plane.chunks_exact( width / shared_count).zip( v_plane.chunks_exact( width / shared_count) ) )
.map( | ( rows, ( u, v ) ) |
.flat_map( | ( rows, ( u, v ) ) |
{
let ( first, second ) = rows.split_at( width );
let mut result = convert_consecutive_planar( first, u, v, shared_count );
result.append( &mut convert_consecutive_planar( second, u, v, shared_count ) );
result
})
.flatten()
.collect()
}

Expand All @@ -102,8 +99,7 @@ pub( crate ) mod private
{
y_plane.chunks_exact( shared_count )
.zip( u_plane.iter().zip( v_plane.iter() ) )
.map(| ( lums, ( u, v ) ) | [ yuv_to_rgb( lums[ 0 ], *u, *v ), yuv_to_rgb( lums[ 1 ], *u, *v ) ] )
.flatten()
.flat_map(| ( lums, ( u, v ) ) | [ yuv_to_rgb( lums[ 0 ], *u, *v ), yuv_to_rgb( lums[ 1 ], *u, *v ) ] )
.flatten()
.collect()
}
Expand Down
4 changes: 2 additions & 2 deletions sample/rust/typing_tools_trivial_sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ use typing_tools::*;
fn main()
{
let src = Box::new( true );
assert_eq!( implements!( src => Copy ), false );
assert_eq!( implements!( src => Clone ), true );
assert!( !implements!( src => Copy ) );
assert!( implements!( src => Clone ) );
}

0 comments on commit b5db8f7

Please sign in to comment.