Skip to content

Commit ae2a906

Browse files
authored
Updating for cargo fmt
1 parent 27720da commit ae2a906

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/data_structures/queue_using_singly_linked_list.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! This module is about a queue implemented using a singly linked list
2-
//!
2+
//!
33
//! The queue follows FIFO (First-In First-Out) principle
44
//! The [enqueue] method's time complexity is O(1)
55
//! The [dequeue] method's time complexity is O(1)
@@ -68,17 +68,16 @@ where
6868
T: Debug,
6969
{
7070
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71-
use std::fmt::Write as _;
72-
73-
let mut output = String::from("LinkedListQueue ( elements: [");
74-
71+
write!(f, "LinkedListQueue ( elements: [")?;
72+
let mut is_first = true;
7573
for elem in self.iter() {
76-
let _ = write!(output, " {elem:?} ").is_ok();
74+
if !is_first {
75+
write!(f, ", ")?;
76+
}
77+
is_first = false;
78+
write!(f, "{:?}", elem)?;
7779
}
78-
79-
let _ = write!(output, "], length: {} )", self.len()).is_ok();
80-
81-
write!(f, "{output}")
80+
write!(f, "], length: {} )", self.len())
8281
}
8382
}
8483

@@ -340,8 +339,6 @@ mod tests {
340339
queue.enqueue(2);
341340
queue.enqueue(3);
342341

343-
println!("{:?}", queue.len());
344-
345342
assert_eq!(queue.len(), 3);
346343
}
347344

@@ -398,13 +395,11 @@ mod tests {
398395
#[test]
399396
fn test_get_from_queue() {
400397
let mut queue = LinkedListQueue::new();
401-
402398
queue.enqueue(2);
403399
queue.enqueue(3);
404400
queue.enqueue(5);
405401

406402
let result = queue.get(1);
407-
println!("{result:#?}", );
408403

409404
assert!(result.is_some());
410405
}

0 commit comments

Comments
 (0)