Skip to content

Commit

Permalink
console: add crate-level clippy lints
Browse files Browse the repository at this point in the history
Signed-off-by: Manos Pitsidianakis <[email protected]>
  • Loading branch information
epilys committed Nov 14, 2024
1 parent 8a2a11d commit ad30537
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 97 deletions.
26 changes: 11 additions & 15 deletions vhost-device-console/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use crate::{
vhu_console::VhostUserConsoleBackend,
};

pub(crate) type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, ThisError)]
/// Errors related to low level Console helpers
pub(crate) enum Error {
pub enum Error {
#[error("Invalid socket count: {0}")]
SocketCountInvalid(usize),
#[error("Could not create console backend: {0}")]
Expand All @@ -44,12 +44,12 @@ pub(crate) enum Error {
WrongBackendSocket,
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub struct VuConsoleConfig {
pub(crate) socket_path: PathBuf,
pub(crate) backend: BackendType,
pub(crate) tcp_port: String,
pub(crate) socket_count: u32,
pub socket_path: PathBuf,
pub backend: BackendType,
pub tcp_port: String,
pub socket_count: u32,
}

impl VuConsoleConfig {
Expand Down Expand Up @@ -86,11 +86,7 @@ impl VuConsoleConfig {

/// This is the public API through which an external program starts the
/// vhost-device-console backend server.
pub(crate) fn start_backend_server(
socket: PathBuf,
tcp_addr: String,
backend: BackendType,
) -> Result<()> {
pub fn start_backend_server(socket: PathBuf, tcp_addr: String, backend: BackendType) -> Result<()> {
loop {
let controller = ConsoleController::new(backend);
let arc_controller = Arc::new(RwLock::new(controller));
Expand Down Expand Up @@ -188,7 +184,7 @@ mod tests {
socket_count: 1,
};

assert!(VuConsoleConfig::try_from(args).is_ok());
VuConsoleConfig::try_from(args).unwrap();
}

#[test]
Expand Down Expand Up @@ -230,7 +226,7 @@ mod tests {
socket_count: 1,
};

assert!(VuConsoleConfig::try_from(args).is_ok());
VuConsoleConfig::try_from(args).unwrap();
}

#[test]
Expand All @@ -242,7 +238,7 @@ mod tests {
socket_count: 2,
};

assert!(VuConsoleConfig::try_from(args).is_ok());
VuConsoleConfig::try_from(args).unwrap();
}

fn test_backend_start_and_stop(args: ConsoleArgs) -> Result<()> {
Expand Down
10 changes: 5 additions & 5 deletions vhost-device-console/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub enum BackendType {
}

#[derive(Debug)]
pub(crate) struct ConsoleController {
pub struct ConsoleController {
config: VirtioConsoleConfig,
pub backend: BackendType,
}

impl ConsoleController {
pub(crate) fn new(backend: BackendType) -> ConsoleController {
ConsoleController {
pub fn new(backend: BackendType) -> Self {
Self {
config: VirtioConsoleConfig {
cols: 20.into(),
rows: 20.into(),
Expand All @@ -36,8 +36,8 @@ impl ConsoleController {
}
}

pub(crate) fn config(&self) -> &VirtioConsoleConfig {
trace!("Get config\n");
pub fn config(&self) -> &VirtioConsoleConfig {
trace!("Get config");
&self.config
}
}
44 changes: 38 additions & 6 deletions vhost-device-console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
// Timos Ampelikiotis <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
#![deny(
clippy::undocumented_unsafe_blocks,
/* groups */
clippy::correctness,
clippy::suspicious,
clippy::complexity,
clippy::perf,
clippy::style,
clippy::nursery,
//* restriction */
clippy::dbg_macro,
clippy::rc_buffer,
clippy::as_underscore,
clippy::assertions_on_result_states,
//* pedantic */
clippy::cast_lossless,
clippy::cast_possible_wrap,
clippy::ptr_as_ptr,
clippy::bool_to_int_with_if,
clippy::borrow_as_ptr,
clippy::case_sensitive_file_extension_comparisons,
clippy::cast_lossless,
clippy::cast_ptr_alignment,
clippy::naive_bytecount
)]

mod backend;
mod console;
Expand All @@ -16,7 +41,7 @@ use log::error;

use crate::console::BackendType;

pub(crate) type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;
use crate::backend::{start_backend, Error, VuConsoleConfig};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -54,11 +79,18 @@ impl TryFrom<ConsoleArgs> for VuConsoleConfig {
return Err(Error::WrongBackendSocket);
}

Ok(VuConsoleConfig {
socket_path: args.socket_path,
backend: args.backend,
tcp_port: args.tcp_port,
socket_count: args.socket_count,
let ConsoleArgs {
socket_path,
backend,
tcp_port,
socket_count,
} = args;

Ok(Self {
socket_path,
backend,
tcp_port,
socket_count,
})
}
}
Expand Down
Loading

0 comments on commit ad30537

Please sign in to comment.