Environment variables: Difference between revisions

Added Rust
No edit summary
(Added Rust)
Line 982:
Default Dir is : c:\rbp101
</pre>
 
=={{header|Rust}}==
<lang Rust>use std::env;
 
fn main() {
println!("{:?}", env::var("HOME"));
println!();
for (k, v) in env::vars().filter(|(k, _)| k.starts_with('P')) {
println!("{}: {}", k, v);
}
}
</lang>
{{out}}
<pre>Ok("/root")
 
PATH: /root/.cargo/bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PLAYGROUND_EDITION: 2018
PLAYGROUND_TIMEOUT: 10
PWD: /playground</pre>
Note that <code>var_os</code> and <code>vars_os</code> are also available, which produce <code>OsString</code> instead of <code>String</code>, offering compatibility with non-utf8 systems.
 
=={{header|Scala}}==
Anonymous user