11#![ allow( fuzzy_provenance_casts) ] // FIXME: this module systematically confuses pointers and integers
22
3+ pub use super :: common:: Env ;
34use crate :: collections:: HashMap ;
45use crate :: ffi:: { OsStr , OsString } ;
6+ use crate :: io;
57use crate :: sync:: atomic:: { AtomicUsize , Ordering } ;
68use crate :: sync:: { Mutex , Once } ;
7- use crate :: { fmt, io, vec} ;
89
910// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1011#[ cfg_attr( test, linkage = "available_externally" ) ]
@@ -27,61 +28,13 @@ fn create_env_store() -> &'static EnvStore {
2728 unsafe { & * ( ENV . load ( Ordering :: Relaxed ) as * const EnvStore ) }
2829}
2930
30- pub struct Env {
31- iter : vec:: IntoIter < ( OsString , OsString ) > ,
32- }
33-
34- // FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
35- pub struct EnvStrDebug < ' a > {
36- slice : & ' a [ ( OsString , OsString ) ] ,
37- }
38-
39- impl fmt:: Debug for EnvStrDebug < ' _ > {
40- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
41- let Self { slice } = self ;
42- f. debug_list ( )
43- . entries ( slice. iter ( ) . map ( |( a, b) | ( a. to_str ( ) . unwrap ( ) , b. to_str ( ) . unwrap ( ) ) ) )
44- . finish ( )
45- }
46- }
47-
48- impl Env {
49- pub fn str_debug ( & self ) -> impl fmt:: Debug + ' _ {
50- let Self { iter } = self ;
51- EnvStrDebug { slice : iter. as_slice ( ) }
52- }
53- }
54-
55- impl fmt:: Debug for Env {
56- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
57- let Self { iter } = self ;
58- f. debug_list ( ) . entries ( iter. as_slice ( ) ) . finish ( )
59- }
60- }
61-
62- impl !Send for Env { }
63- impl !Sync for Env { }
64-
65- impl Iterator for Env {
66- type Item = ( OsString , OsString ) ;
67- fn next ( & mut self ) -> Option < ( OsString , OsString ) > {
68- self . iter . next ( )
69- }
70- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
71- self . iter . size_hint ( )
72- }
73- }
74-
7531pub fn env ( ) -> Env {
7632 let clone_to_vec = |map : & HashMap < OsString , OsString > | -> Vec < _ > {
7733 map. iter ( ) . map ( |( k, v) | ( k. clone ( ) , v. clone ( ) ) ) . collect ( )
7834 } ;
7935
80- let iter = get_env_store ( )
81- . map ( |env| clone_to_vec ( & env. lock ( ) . unwrap ( ) ) )
82- . unwrap_or_default ( )
83- . into_iter ( ) ;
84- Env { iter }
36+ let env = get_env_store ( ) . map ( |env| clone_to_vec ( & env. lock ( ) . unwrap ( ) ) ) . unwrap_or_default ( ) ;
37+ Env :: new ( env)
8538}
8639
8740pub fn getenv ( k : & OsStr ) -> Option < OsString > {
0 commit comments