Skip to content

Commit ad30537

Browse files
committed
console: add crate-level clippy lints
Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent 8a2a11d commit ad30537

File tree

5 files changed

+126
-97
lines changed

5 files changed

+126
-97
lines changed

vhost-device-console/src/backend.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ use crate::{
2323
vhu_console::VhostUserConsoleBackend,
2424
};
2525

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

2828
#[derive(Debug, ThisError)]
2929
/// Errors related to low level Console helpers
30-
pub(crate) enum Error {
30+
pub enum Error {
3131
#[error("Invalid socket count: {0}")]
3232
SocketCountInvalid(usize),
3333
#[error("Could not create console backend: {0}")]
@@ -44,12 +44,12 @@ pub(crate) enum Error {
4444
WrongBackendSocket,
4545
}
4646

47-
#[derive(PartialEq, Debug)]
47+
#[derive(PartialEq, Eq, Debug)]
4848
pub struct VuConsoleConfig {
49-
pub(crate) socket_path: PathBuf,
50-
pub(crate) backend: BackendType,
51-
pub(crate) tcp_port: String,
52-
pub(crate) socket_count: u32,
49+
pub socket_path: PathBuf,
50+
pub backend: BackendType,
51+
pub tcp_port: String,
52+
pub socket_count: u32,
5353
}
5454

5555
impl VuConsoleConfig {
@@ -86,11 +86,7 @@ impl VuConsoleConfig {
8686

8787
/// This is the public API through which an external program starts the
8888
/// vhost-device-console backend server.
89-
pub(crate) fn start_backend_server(
90-
socket: PathBuf,
91-
tcp_addr: String,
92-
backend: BackendType,
93-
) -> Result<()> {
89+
pub fn start_backend_server(socket: PathBuf, tcp_addr: String, backend: BackendType) -> Result<()> {
9490
loop {
9591
let controller = ConsoleController::new(backend);
9692
let arc_controller = Arc::new(RwLock::new(controller));
@@ -188,7 +184,7 @@ mod tests {
188184
socket_count: 1,
189185
};
190186

191-
assert!(VuConsoleConfig::try_from(args).is_ok());
187+
VuConsoleConfig::try_from(args).unwrap();
192188
}
193189

194190
#[test]
@@ -230,7 +226,7 @@ mod tests {
230226
socket_count: 1,
231227
};
232228

233-
assert!(VuConsoleConfig::try_from(args).is_ok());
229+
VuConsoleConfig::try_from(args).unwrap();
234230
}
235231

236232
#[test]
@@ -242,7 +238,7 @@ mod tests {
242238
socket_count: 2,
243239
};
244240

245-
assert!(VuConsoleConfig::try_from(args).is_ok());
241+
VuConsoleConfig::try_from(args).unwrap();
246242
}
247243

248244
fn test_backend_start_and_stop(args: ConsoleArgs) -> Result<()> {

vhost-device-console/src/console.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ pub enum BackendType {
1818
}
1919

2020
#[derive(Debug)]
21-
pub(crate) struct ConsoleController {
21+
pub struct ConsoleController {
2222
config: VirtioConsoleConfig,
2323
pub backend: BackendType,
2424
}
2525

2626
impl ConsoleController {
27-
pub(crate) fn new(backend: BackendType) -> ConsoleController {
28-
ConsoleController {
27+
pub fn new(backend: BackendType) -> Self {
28+
Self {
2929
config: VirtioConsoleConfig {
3030
cols: 20.into(),
3131
rows: 20.into(),
@@ -36,8 +36,8 @@ impl ConsoleController {
3636
}
3737
}
3838

39-
pub(crate) fn config(&self) -> &VirtioConsoleConfig {
40-
trace!("Get config\n");
39+
pub fn config(&self) -> &VirtioConsoleConfig {
40+
trace!("Get config");
4141
&self.config
4242
}
4343
}

vhost-device-console/src/main.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@
44
// Timos Ampelikiotis <[email protected]>
55
//
66
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
7+
#![deny(
8+
clippy::undocumented_unsafe_blocks,
9+
/* groups */
10+
clippy::correctness,
11+
clippy::suspicious,
12+
clippy::complexity,
13+
clippy::perf,
14+
clippy::style,
15+
clippy::nursery,
16+
//* restriction */
17+
clippy::dbg_macro,
18+
clippy::rc_buffer,
19+
clippy::as_underscore,
20+
clippy::assertions_on_result_states,
21+
//* pedantic */
22+
clippy::cast_lossless,
23+
clippy::cast_possible_wrap,
24+
clippy::ptr_as_ptr,
25+
clippy::bool_to_int_with_if,
26+
clippy::borrow_as_ptr,
27+
clippy::case_sensitive_file_extension_comparisons,
28+
clippy::cast_lossless,
29+
clippy::cast_ptr_alignment,
30+
clippy::naive_bytecount
31+
)]
732

833
mod backend;
934
mod console;
@@ -16,7 +41,7 @@ use log::error;
1641

1742
use crate::console::BackendType;
1843

19-
pub(crate) type Result<T> = std::result::Result<T, Error>;
44+
pub type Result<T> = std::result::Result<T, Error>;
2045
use crate::backend::{start_backend, Error, VuConsoleConfig};
2146

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

57-
Ok(VuConsoleConfig {
58-
socket_path: args.socket_path,
59-
backend: args.backend,
60-
tcp_port: args.tcp_port,
61-
socket_count: args.socket_count,
82+
let ConsoleArgs {
83+
socket_path,
84+
backend,
85+
tcp_port,
86+
socket_count,
87+
} = args;
88+
89+
Ok(Self {
90+
socket_path,
91+
backend,
92+
tcp_port,
93+
socket_count,
6294
})
6395
}
6496
}

0 commit comments

Comments
 (0)