1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use std::ffi::{OsStr, OsString};
use std::fmt;
use crate::sys;
use heim_common::prelude::wrap;
pub struct Environment(sys::Environment);
wrap!(Environment, sys::Environment);
impl Environment {
pub fn iter(&self) -> EnvironmentIter<'_> {
EnvironmentIter::from(self.0.iter())
}
}
impl fmt::Debug for Environment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_map().entries(self.iter()).finish()
}
}
impl IntoIterator for Environment {
type Item = (OsString, OsString);
type IntoIter = IntoEnvironmentIter;
fn into_iter(self) -> Self::IntoIter {
IntoEnvironmentIter::from(self.0.into_iter())
}
}
impl<'e> IntoIterator for &'e Environment {
type Item = (&'e OsStr, &'e OsStr);
type IntoIter = EnvironmentIter<'e>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
#[derive(Debug)]
pub struct IntoEnvironmentIter(sys::IntoEnvironmentIter);
wrap!(IntoEnvironmentIter, sys::IntoEnvironmentIter);
impl Iterator for IntoEnvironmentIter {
type Item = (OsString, OsString);
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
}
#[derive(Debug)]
pub struct EnvironmentIter<'e>(sys::EnvironmentIter<'e>);
wrap!('e, EnvironmentIter<'e>, sys::EnvironmentIter<'e>);
impl<'e> Iterator for EnvironmentIter<'e> {
type Item = (&'e OsStr, &'e OsStr);
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}
}