use core::fmt::{self, Display, Formatter};
use core::ops::Deref;
use crate::error::PropertyError;
use crate::fdt::{Fdt, FdtNode};
use crate::{Node, Property};
impl<'a> Fdt<'a> {
#[must_use]
pub fn chosen(self) -> Option<Chosen<FdtNode<'a>>> {
let node = self.find_node("/chosen")?;
Some(Chosen { node })
}
}
#[derive(Clone, Copy, Debug)]
pub struct Chosen<N> {
node: N,
}
impl<N> Deref for Chosen<N> {
type Target = N;
fn deref(&self) -> &Self::Target {
&self.node
}
}
impl<N: Display> Display for Chosen<N> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
self.node.fmt(f)
}
}
impl<'a, N: Node<'a>> Chosen<N> {
pub fn bootargs(&self) -> Result<Option<&'a str>, PropertyError> {
self.node
.property("bootargs")
.map(|value| value.as_str())
.transpose()
}
pub fn stdout_path(&self) -> Result<Option<&'a str>, PropertyError> {
self.node
.property("stdout-path")
.map(|value| value.as_str())
.transpose()
}
pub fn stdin_path(&self) -> Result<Option<&'a str>, PropertyError> {
self.node
.property("stdin-path")
.map(|value| value.as_str())
.transpose()
}
}