fix(02-01): fix clippy warnings to pass lint checks
- config.rs: Added Default derive, removed manual impl - template.rs: Simplified iterator with flatten() - camera/linux.rs: Added transmute annotations, fixed doc syntax - camera/mod.rs: Allow unused imports from linux module - ipc.rs: Renamed default() to with_default_path(), simplified closures - secure_memory.rs: Use is_multiple_of() instead of modulo - phase3_security_test.rs: Use std::f32::consts::PI
This commit is contained in:
@@ -83,7 +83,7 @@ use crate::error::{Error, Result};
|
||||
/// assert_eq!(config.general.timeout_seconds, 5);
|
||||
/// assert!(config.anti_spoofing.enabled);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub general: GeneralConfig,
|
||||
@@ -335,19 +335,6 @@ impl Default for TpmConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
general: GeneralConfig::default(),
|
||||
camera: CameraConfig::default(),
|
||||
detection: DetectionConfig::default(),
|
||||
embedding: EmbeddingConfig::default(),
|
||||
anti_spoofing: AntiSpoofingConfig::default(),
|
||||
tpm: TpmConfig::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Load configuration from a TOML file
|
||||
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||||
|
||||
@@ -316,11 +316,9 @@ impl TemplateStore {
|
||||
|
||||
// Check if directory has any template files
|
||||
if let Ok(entries) = fs::read_dir(&user_dir) {
|
||||
for entry in entries {
|
||||
if let Ok(entry) = entry {
|
||||
if entry.path().extension().and_then(|s| s.to_str()) == Some("json") {
|
||||
return true;
|
||||
}
|
||||
for entry in entries.flatten() {
|
||||
if entry.path().extension().and_then(|s| s.to_str()) == Some("json") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ impl Camera {
|
||||
};
|
||||
|
||||
// Store as 'static - we ensure device outlives stream
|
||||
self.stream = Some(unsafe { std::mem::transmute(stream) });
|
||||
self.stream = Some(unsafe { std::mem::transmute::<Stream<'_>, Stream<'static>>(stream) });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ mod ir_emitter;
|
||||
mod linux;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[allow(unused_imports)]
|
||||
pub use linux::*;
|
||||
|
||||
// IrEmitterControl is exported for use in tests and external code
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
//!
|
||||
//! #[tokio::main]
|
||||
//! async fn main() {
|
||||
//! let client = IpcClient::default();
|
||||
//! let client = IpcClient::with_default_path();
|
||||
//!
|
||||
//! // Check if daemon is running
|
||||
//! if client.ping().await.unwrap() {
|
||||
@@ -756,7 +756,7 @@ impl IpcClient {
|
||||
}
|
||||
|
||||
/// Create a client with the default socket path
|
||||
pub fn default() -> Self {
|
||||
pub fn with_default_path() -> Self {
|
||||
Self::new(IpcServer::default_socket_path())
|
||||
}
|
||||
|
||||
@@ -820,7 +820,7 @@ impl IpcClient {
|
||||
"Connection timeout",
|
||||
))
|
||||
})?
|
||||
.map_err(|e| Error::Io(e))?;
|
||||
.map_err(Error::Io)?;
|
||||
|
||||
let request_json =
|
||||
serde_json::to_string(request).map_err(|e| Error::Serialization(e.to_string()))?;
|
||||
@@ -837,7 +837,7 @@ impl IpcClient {
|
||||
"Read timeout",
|
||||
))
|
||||
})?
|
||||
.map_err(|e| Error::Io(e))?;
|
||||
.map_err(Error::Io)?;
|
||||
|
||||
if n == 0 {
|
||||
return Err(Error::Io(std::io::Error::new(
|
||||
|
||||
@@ -82,17 +82,6 @@ impl SecureEmbedding {
|
||||
}
|
||||
}
|
||||
|
||||
/// Unlock memory when dropping (called by Drop implementation)
|
||||
fn try_unlock_memory(&self) {
|
||||
let byte_slice = unsafe {
|
||||
std::slice::from_raw_parts(
|
||||
self.data.as_ptr() as *const u8,
|
||||
self.data.len() * std::mem::size_of::<f32>(),
|
||||
)
|
||||
};
|
||||
let _ = memory_protection::unlock_memory(byte_slice);
|
||||
}
|
||||
|
||||
/// Get the embedding dimension
|
||||
pub fn len(&self) -> usize {
|
||||
self.data.len()
|
||||
@@ -189,7 +178,7 @@ impl SecureEmbedding {
|
||||
|
||||
/// Deserialize from bytes
|
||||
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
|
||||
if bytes.len() % 4 != 0 {
|
||||
if !bytes.len().is_multiple_of(4) {
|
||||
return Err(Error::Serialization(
|
||||
"Invalid embedding byte length".to_string(),
|
||||
));
|
||||
|
||||
@@ -114,7 +114,7 @@ fn test_secure_embedding_similarity_metrics() {
|
||||
|
||||
#[test]
|
||||
fn test_secure_embedding_serialization() {
|
||||
let original = SecureEmbedding::new(vec![1.5, -2.5, 3.14159, 0.0, f32::MAX]);
|
||||
let original = SecureEmbedding::new(vec![1.5, -2.5, std::f32::consts::PI, 0.0, f32::MAX]);
|
||||
let bytes = original.to_bytes();
|
||||
let restored = SecureEmbedding::from_bytes(&bytes).unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user