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
impl NameString
pub fn empty() -> Self
pub fn new<T: Copy + Into<NameSeg>>(path: &[T]) -> Self
pub fn new_root<T: Copy + Into<NameSeg>>(path: &[T]) -> Self
pub fn new_parent<T: Copy + Into<NameSeg>>(n: usize, path: &[T]) -> Self
Sourcepub fn resolve_as_decl(&self, scope: &[NameSeg]) -> Option<Vec<NameSeg>>
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.
Sourcepub fn resolve_as_ref(&self, scope: &[NameSeg]) -> Vec<Vec<NameSeg>>
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
impl Clone for NameString
Source§fn clone(&self) -> NameString
fn clone(&self) -> NameString
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for NameString
impl Debug for NameString
Source§impl Display for NameString
impl Display for NameString
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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<NameSeg> for NameString
impl From<NameSeg> for NameString
Source§fn from(n: NameSeg) -> NameString
fn from(n: NameSeg) -> NameString
Source§impl<'a> From<NameString> for PackageElement<'a>
impl<'a> From<NameString> for PackageElement<'a>
Source§fn from(n: NameString) -> PackageElement<'a>
fn from(n: NameString) -> PackageElement<'a>
Source§impl From<NameString> for SimpleName
impl From<NameString> for SimpleName
Source§fn from(n: NameString) -> SimpleName
fn from(n: NameString) -> SimpleName
Source§impl<'a> From<NameString> for SuperName<'a>
impl<'a> From<NameString> for SuperName<'a>
Source§fn from(n: NameString) -> SuperName<'a>
fn from(n: NameString) -> SuperName<'a>
Source§impl<'a> From<NameString> for TermArg<'a>
impl<'a> From<NameString> for TermArg<'a>
Source§fn from(n: NameString) -> TermArg<'a>
fn from(n: NameString) -> TermArg<'a>
Source§impl<'a> Parse<'a> for NameString
Grammar:
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