pub struct Environ { /* private fields */ }
Expand description
Environ, short for environment, is a collection of key-value pairs that are used to:
- Dependency injection. Especially channels connected to dependent services.
- Configuration settings.
- Command-line arguments (shell is not available as of this writing though!).
- The
VmSpace
of the current process. To manage its own address space.
§Environ is a key-value store
The keys are always strings, and the values can be of different types. Currently, the supported types are:
- Channel.
- VmSpace.
- A list of found devices (for device drivers).
§How to request environ items
To request an environ item,
§Examples
pub fn main(mut env: Environ) {
// Dump all environ items.
info!("env: {:#?}", env);
// Take the ownership of the channel.
let driver_ch: Channel = env.take_channel("dep:ethernet_device").unwrap();
}
This snippet logs:
[tcpip ] INFO env: {
"dep:ethernet_device": Channel(
Channel(#1),
),
"dep:startup": Channel(
Channel(#2),
),
}
§Difference from environment variables
Environ is similar to environment variables in POSIX, and actually, internal implementation is mostly the same (both key and value are strings). However, the key difference is that Starina enforces convention on key names so that we can provide a consistent and type-safe API.
Otherwise, each application would have different command-line parsers.
Implementations§
Source§impl Environ
impl Environ
Sourcepub fn take_channel(&mut self, key: &str) -> Option<Channel>
pub fn take_channel(&mut self, key: &str) -> Option<Channel>
Returns the channel associated with the key.
If the key is not found, or is already taken, None
is returned.
§Panics
Panics if the value associated with the key is not a channel.
Sourcepub fn take_vmspace(&mut self, key: &str) -> Option<VmSpace>
pub fn take_vmspace(&mut self, key: &str) -> Option<VmSpace>
Returns the vmspace associated with the key.
If the key is not found, or is already taken, None
is returned.
§Panics
Panics if the value associated with the key is not a vmspace.
Sourcepub fn devices(&self, key: &str) -> Option<&[Device]>
pub fn devices(&self, key: &str) -> Option<&[Device]>
Returns the devices associated with the key.