Skip to content

Commit

Permalink
Apply suggestions from @clux's code review
Browse files Browse the repository at this point in the history
* Remove redundant `.items` acess.
* Rename NodeMetric to NodeMetrics
* std::cmp instead of manually comparing.

Co-authored-by: Eirik A <sszynrae@gmail.com>
Signed-off-by: Matei David <matei.david.35@gmail.com>
  • Loading branch information
mateiidavid and clux authored Oct 30, 2023
1 parent 2419a4c commit 44980d4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions examples/request_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> anyhow::Result<()> {
let api: Api<Node> = Api::all(client.clone());
let nodes = api.list(&ListParams::default()).await?;

let node_names = nodes.items.iter().map(|n| n.name_any()).collect();
let node_names = nodes.iter().map(|n| n.name_any()).collect();
let mut table = Table::new(node_names);

for node in nodes.items {
Expand Down Expand Up @@ -60,7 +60,7 @@ struct Table {
/// Represents a row in the stat table. A metric is associated with a node and
/// collects information on the CPU and memory usage
#[derive(Debug, Deserialize)]
struct NodeMetric {
struct NodeMetrics {
#[serde(rename = "nodeName")]
name: String,
cpu: Metric,
Expand Down Expand Up @@ -136,11 +136,7 @@ impl Table {

fn find_header_len(node_names: Vec<String>) -> usize {
let max_name_len = node_names.iter().map(|n| n.len()).max().unwrap_or_else(|| 0);
if max_name_len > headers::NAME.len() {
max_name_len
} else {
headers::NAME.len()
}
std::cmp::max(max_name_len, headers::NAME.len())
}
}

Expand Down

0 comments on commit 44980d4

Please sign in to comment.