Mercurial > crates > nonstick
comparison src/environ.rs @ 141:a508a69c068a
Remove a lot of Results from functions.
Many functions are documented to only return failing Results when given
improper inputs or when there is a memory allocation failure (which
can be verified by looking at the source). In cases where we know our
input is correct, we don't need to check for memory allocation errors
for the same reason that Rust doesn't do so when you, e.g., create a
new Vec.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 05 Jul 2025 17:16:56 -0400 |
parents | 3f11b8d30f63 |
children |
comparison
equal
deleted
inserted
replaced
140:add7228adb2f | 141:a508a69c068a |
---|---|
1 //! Traits and stuff for managing the environment of a PAM handle. | 1 //! Traits and stuff 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 crate::constants::Result; | |
7 use std::ffi::{OsStr, OsString}; | 6 use std::ffi::{OsStr, OsString}; |
8 | 7 |
9 /// A key/value map for environment variables, as [`OsString`]s. | 8 /// A key/value map for environment variables, as [`OsString`]s. |
10 /// | 9 /// |
11 /// This is a limited subset of what [`HashMap`](std::collections::HashMap) | 10 /// This is a limited subset of what [`HashMap`](std::collections::HashMap) |
13 pub trait EnvironMap<'a> { | 12 pub trait EnvironMap<'a> { |
14 /// Gets the environment variable of the given key. | 13 /// Gets the environment variable of the given key. |
15 fn get(&self, key: impl AsRef<OsStr>) -> Option<OsString>; | 14 fn get(&self, key: impl AsRef<OsStr>) -> Option<OsString>; |
16 | 15 |
17 /// Iterates over the key/value pairs of the environment. | 16 /// Iterates over the key/value pairs of the environment. |
18 fn iter(&self) -> Result<impl Iterator<Item = (OsString, OsString)>>; | 17 fn iter(&self) -> impl Iterator<Item = (OsString, OsString)>; |
19 } | 18 } |
20 | 19 |
21 pub trait EnvironMapMut<'a>: EnvironMap<'a> { | 20 pub trait EnvironMapMut<'a>: EnvironMap<'a> { |
22 /// Sets the environment variable with the given key, | 21 /// Sets the environment variable with the given key, |
23 /// returning the old one if present. | 22 /// returning the old one if present. |
24 fn insert( | 23 fn insert(&mut self, key: impl AsRef<OsStr>, val: impl AsRef<OsStr>) -> Option<OsString>; |
25 &mut self, | |
26 key: impl AsRef<OsStr>, | |
27 val: impl AsRef<OsStr>, | |
28 ) -> Result<Option<OsString>>; | |
29 | 24 |
30 /// Removes the environment variable from the map, returning its old value | 25 /// Removes the environment variable from the map, returning its old value |
31 /// if present. | 26 /// if present. |
32 fn remove(&mut self, key: impl AsRef<OsStr>) -> Result<Option<OsString>>; | 27 fn remove(&mut self, key: impl AsRef<OsStr>) -> Option<OsString>; |
33 } | 28 } |