starina_api::environ

Struct Environ

Source
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

Source

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.

Source

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.

Source

pub fn devices(&self, key: &str) -> Option<&[Device]>

Returns the devices associated with the key.

Source

pub fn string(&self, key: &str) -> Option<&str>

Trait Implementations§

Source§

impl Debug for Environ

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.