Skip to content

Commit 343a13c

Browse files
committed
Update doc comment code
1 parent 1172e71 commit 343a13c

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/libproc/proc_pid.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -519,25 +519,20 @@ pub trait ListPIDInfo {
519519
///
520520
/// ```
521521
/// use std::io::Write;
522-
/// use libproc::libproc::proc_pid::{listpidinfo, pidinfo, ListFDs, ListThreads, TaskAllInfo};
522+
/// use libproc::libproc::proc_pid::{listpidinfo, pidinfo, ListFDs, TaskAllInfo, ProcFDType};
523523
///
524-
/// fn listthreads_test() {
524+
/// fn listpidinfo_test() {
525525
/// use std::process;
526526
/// let pid = process::id() as i32;
527527
///
528-
/// match pidinfo::<TaskAllInfo>(pid, 0) {
529-
/// Ok(info) => {
530-
/// match listpidinfo::<ListThreads>(pid, info.ptinfo.pti_threadnum as usize) {
531-
/// Ok(threads) => assert!(threads.len()>0),
532-
/// Err(err) => assert!(false, "Error retrieving process info: {}", err)
528+
/// if Ok(info) = pidinfo::<TaskAllInfo>(pid, 0) {
529+
/// if Ok(fds) = listpidinfo::<ListFDs>(pid, info.pbsd.pbi_nfiles as usize) {
530+
/// for fd in &fds {
531+
/// let fd_type = ProcFDType::from(fd.proc_fdtype);
532+
/// println!("File Descriptor: {}, Type: {}", fd.proc_fd, fd_type);
533533
/// }
534-
/// match listpidinfo::<ListFDs>(pid, info.pbsd.pbi_nfiles as usize) {
535-
/// Ok(fds) => assert!(fds.len()>0),
536-
/// Err(err) => assert!(false, "Error retrieving process info: {}", err)
537-
/// }
538-
/// },
539-
/// Err(err) => assert!(false, "Error retrieving process info: {}", err)
540-
/// };
534+
/// }
535+
/// }
541536
/// }
542537
/// ```
543538
pub fn listpidinfo<T: ListPIDInfo>(pid : i32, max_len: usize) -> Result<Vec<T::Item>, String> {
@@ -564,6 +559,26 @@ pub fn listpidinfo<T: ListPIDInfo>(pid : i32, max_len: usize) -> Result<Vec<T::I
564559
}
565560
}
566561

562+
#[test]
563+
fn listpidinfo_test() {
564+
use std::process;
565+
let pid = process::id() as i32;
566+
567+
match pidinfo::<TaskAllInfo>(pid, 0) {
568+
Ok(info) => {
569+
match listpidinfo::<ListThreads>(pid, info.ptinfo.pti_threadnum as usize) {
570+
Ok(threads) => assert!(threads.len()>0),
571+
Err(err) => assert!(false, "Error retrieving process info: {}", err)
572+
}
573+
match listpidinfo::<ListFDs>(pid, info.pbsd.pbi_nfiles as usize) {
574+
Ok(fds) => assert!(fds.len()>0),
575+
Err(err) => assert!(false, "Error retrieving process info: {}", err)
576+
}
577+
},
578+
Err(err) => assert!(false, "Error retrieving process info: {}", err)
579+
};
580+
}
581+
567582
pub struct ListThreads;
568583

569584
impl ListPIDInfo for ListThreads {

0 commit comments

Comments
 (0)