Mercurial > crates > nonstick
comparison src/environ.rs @ 193:5074d8e00560
Doc improvements.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 02 Aug 2025 19:49:21 -0400 |
parents | a508a69c068a |
children |
comparison
equal
deleted
inserted
replaced
192:4c39eaa4a5ae | 193:5074d8e00560 |
---|---|
1 //! Traits and stuff for managing the environment of a PAM handle. | 1 //! Traits for managing the environment of a PAM handle. |
2 //! | 2 //! |
3 //! PAM modules can set environment variables to apply to a user session. | 3 //! PAM modules can set environment variables to apply to a user session. |
4 //! This module manages the interface for doing all of that. | 4 //! This module manages the interface for doing all of that. |
5 | 5 |
6 use std::ffi::{OsStr, OsString}; | 6 use std::ffi::{OsStr, OsString}; |
7 | 7 |
8 /// A key/value map for environment variables, as [`OsString`]s. | 8 /// A read-only key/value map for environment variables, as [`OsString`]s. |
9 /// | |
10 /// This is a limited subset of what [`HashMap`](std::collections::HashMap) | |
11 /// can do. Notably, we do *not* support mutable iteration. | |
12 pub trait EnvironMap<'a> { | 9 pub trait EnvironMap<'a> { |
13 /// Gets the environment variable of the given key. | 10 /// Gets the environment variable of the given key. |
14 fn get(&self, key: impl AsRef<OsStr>) -> Option<OsString>; | 11 fn get(&self, key: impl AsRef<OsStr>) -> Option<OsString>; |
15 | 12 |
16 /// Iterates over the key/value pairs of the environment. | 13 /// Iterates over the key/value pairs of the environment. |
17 fn iter(&self) -> impl Iterator<Item = (OsString, OsString)>; | 14 fn iter(&self) -> impl Iterator<Item = (OsString, OsString)>; |
18 } | 15 } |
19 | 16 |
17 /// A read/write key/value map for environment variables as [`OsString`]s. | |
18 /// | |
19 /// This is a limited subset of what [`HashMap`](std::collections::HashMap) | |
20 /// can do. Notably, we do *not* support mutable iteration. | |
20 pub trait EnvironMapMut<'a>: EnvironMap<'a> { | 21 pub trait EnvironMapMut<'a>: EnvironMap<'a> { |
21 /// Sets the environment variable with the given key, | 22 /// Sets the environment variable with the given key, |
22 /// returning the old one if present. | 23 /// returning the old one if present. |
23 fn insert(&mut self, key: impl AsRef<OsStr>, val: impl AsRef<OsStr>) -> Option<OsString>; | 24 fn insert(&mut self, key: impl AsRef<OsStr>, val: impl AsRef<OsStr>) -> Option<OsString>; |
24 | 25 |