diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2018-10-30 20:58:55 +0100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-30 12:58:55 -0700 |
| commit | 946acbc559fab050d13b5f2f66088254ec96f83d (patch) | |
| tree | 93cd12b60e8d91a482b550949c857bbf4a83cbd0 /src/resources.rs | |
| parent | 8b39d2c99ef41736bb1d5b74ccda2f3aa6223e84 (diff) | |
Add resources op (#1119)
Diffstat (limited to 'src/resources.rs')
| -rw-r--r-- | src/resources.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/resources.rs b/src/resources.rs index a959d5c55..72fdf9777 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -58,6 +58,40 @@ enum Repr { TcpStream(tokio::net::TcpStream), } +pub fn table_entries() -> Vec<(i32, String)> { + let table = RESOURCE_TABLE.lock().unwrap(); + + let tuples = table + .iter() + .map(|(key, value)| (key.clone(), inspect_repr(&value))) + .collect(); + + tuples +} + +#[test] +fn test_table_entries() { + let mut entries = table_entries(); + entries.sort(); + assert_eq!(entries.len(), 3); + assert_eq!(entries[0], (0, String::from("stdin"))); + assert_eq!(entries[1], (1, String::from("stdout"))); + assert_eq!(entries[2], (2, String::from("stderr"))); +} + +fn inspect_repr(repr: &Repr) -> String { + let h_repr = match repr { + Repr::Stdin(_) => "stdin", + Repr::Stdout(_) => "stdout", + Repr::Stderr(_) => "stderr", + Repr::FsFile(_) => "fsFile", + Repr::TcpListener(_) => "tcpListener", + Repr::TcpStream(_) => "tcpStream", + }; + + String::from(h_repr) +} + // Abstract async file interface. // Ideally in unix, if Resource represents an OS rid, it will be the same. #[derive(Debug)] |
