Struct NameString

Source
pub struct NameString {
    pub anchor: PathAnchor,
    pub path: Vec<NameSeg>,
}
Expand description

Fully qualified object path, either absolute or relative.

Fields§

§anchor: PathAnchor

Specifies how to resolve this path as absolute or relative.

§path: Vec<NameSeg>

Segments of the path

Implementations§

Source§

impl NameString

Source

pub fn empty() -> Self

Source

pub fn new<T: Copy + Into<NameSeg>>(path: &[T]) -> Self

Source

pub fn new_root<T: Copy + Into<NameSeg>>(path: &[T]) -> Self

Source

pub fn new_parent<T: Copy + Into<NameSeg>>(n: usize, path: &[T]) -> Self

Source

pub fn resolve_as_decl(&self, scope: &[NameSeg]) -> Option<Vec<NameSeg>>

Convert to an absolute namespace path in the context of the given scope, treating the name as new declaration/definition.

If this name is a reference that must be looked up in the namespace, then use NameString::resolve_as_ref instead.

let scope = to_path(&[b"A___", b"B___"]);

let child = NameString::new(&[b"X___"]);
let up_1  = NameString::new_parent(1, &[b"X___"]);
let up_2  = NameString::new_parent(2, &[b"X___"]);
let up_3  = NameString::new_parent(3, &[b"X___"]);
let abs   = NameString::new_root(&[b"Y___", b"Z___"]);

assert_eq!(child.resolve_as_decl(&scope), Some(to_path(&[b"A___", b"B___", b"X___"])));
assert_eq!(up_1.resolve_as_decl(&scope),  Some(to_path(&[b"A___", b"X___"])));
assert_eq!(up_2.resolve_as_decl(&scope),  Some(to_path(&[b"X___"])));
assert_eq!(up_3.resolve_as_decl(&scope),  None);
assert_eq!(abs.resolve_as_decl(&scope),   Some(to_path(&[b"Y___", b"Z___"])));
§Errors

Returns None if this NameString is anchored to a parent scope and the result would be outside the namespace root.

Source

pub fn resolve_as_ref(&self, scope: &[NameSeg]) -> Vec<Vec<NameSeg>>

List all possible absolute pathnames that this name may refer to in the context of the given scope.

Use this method if the name is a reference that must be looked up in the namespace. For names that define new objects, see NameString::resolve_as_decl.

As defined by §5.3 of ACPI 6.3, there are distinct rules for two cases:

  • Unanchored one-segment names are looked up in the current scope, then the parent scope, etc. until a match is found.
  • All other names are resolved relative to the current scope only.
let scope = to_path(&[b"A___", b"B___"]);

let simple = NameString::new(&[b"X___"]);
let multi  = NameString::new(&[b"X___", b"Y___"]);
let up_1   = NameString::new_parent(1, &[b"X___"]);
let up_2   = NameString::new_parent(2, &[b"X___"]);
let up_3   = NameString::new_parent(3, &[b"X___"]);

// Look up unanchored one-segment names in parent scopes
assert_eq!(
    simple.resolve_as_ref(&scope),
    vec![
        to_path(&[b"A___", b"B___", b"X___"]),
        to_path(&[b"A___", b"X___"]),
        to_path(&[b"X___"]),
    ],
);

// Others only resolve against current scope
assert_eq!(multi.resolve_as_ref(&scope), vec![to_path(&[b"A___", b"B___", b"X___", b"Y___"])]);
assert_eq!(up_1.resolve_as_ref(&scope),  vec![to_path(&[b"A___", b"X___"])]);
assert_eq!(up_2.resolve_as_ref(&scope),  vec![to_path(&[b"X___"])]);
assert_eq!(up_3.resolve_as_ref(&scope),  Vec::<Vec<NameSeg>>::new());

Will return an empty vector if this NameString is anchored to a parent scope and the result would be outside the namespace root.

Trait Implementations§

Source§

impl Clone for NameString

Source§

fn clone(&self) -> NameString

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NameString

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for NameString

Source§

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

Format a NameString like a path in ASL

let a = NameString::empty();
assert_eq!(format!("{}", a), "");

let b = NameString::new(&[b"ASDF", b"_123"]);
assert_eq!(format!("{}", b), "ASDF._123");

let c = NameString::new_parent(2, &[b"FOO_", b"BAR_"]);
assert_eq!(format!("{}", c), "^^FOO_.BAR_");

let d = NameString::new_root(&[b"X___"]);
assert_eq!(format!("{}", d), "\\X___");
Source§

impl From<&[u8; 4]> for NameString

Source§

fn from(n: &[u8; 4]) -> NameString

Converts to this type from the input type.
Source§

impl From<NameSeg> for NameString

Source§

fn from(n: NameSeg) -> NameString

Converts to this type from the input type.
Source§

impl<'a> From<NameString> for PackageElement<'a>

Source§

fn from(n: NameString) -> PackageElement<'a>

Converts to this type from the input type.
Source§

impl From<NameString> for SimpleName

Source§

fn from(n: NameString) -> SimpleName

Converts to this type from the input type.
Source§

impl<'a> From<NameString> for SuperName<'a>

Source§

fn from(n: NameString) -> SuperName<'a>

Converts to this type from the input type.
Source§

impl<'a> From<NameString> for TermArg<'a>

Source§

fn from(n: NameString) -> TermArg<'a>

Converts to this type from the input type.
Source§

impl<'a> Parse<'a> for NameString

Grammar:

NameString       := <RootChar NamePath> | <PrefixPath NamePath>
PrefixPath       := Nothing | <‘^’ PrefixPath>
NamePath         := NameSeg | DualNamePath | MultiNamePath | NullName

RootChar         := ‘\’
ParentPrefixChar := ‘^’

NullName         := 0x00
DualNamePath     := DualNamePrefix NameSeg NameSeg
DualNamePrefix   := 0x2E
MultiNamePath    := MultiNamePrefix SegCount NameSeg(SegCount)
MultiNamePrefix  := 0x2F

SegCount         := ByteData
Source§

fn parse<E: AMLParseError<'a>>( i: ParserState<'a>, ) -> AMLParseResult<'a, Self, E>

Try to parse an object of this type from the given input and state. Read more
Source§

impl PartialEq for NameString

Source§

fn eq(&self, other: &NameString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for NameString

Source§

impl StructuralPartialEq for NameString

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.