pub struct Identifier {
    pub values: Vec<IdentifierValue>,
}
Expand description

An identifier

Examples

networks[0].name
  |      │   |
  |      |   └ IdentifierValue::Name("name")
  |      |
  |      └ IdentifierValue::Index(0)
  |
  └ IdentifierValue::Name("networks")
persons[boss.id]["name"]
  |      │         |
  |      |         └ IdentifierValue::Name("name")
  |      |
  |      └ IdentifierValue::Identifier(boss.id)
  |                                     |   |
  |                                     |   └ IdentifierValue::Name("id")
  |                                     |
  |                                     └ IdentifierValue::Name("boss")
  |
  └ IdentifierValue::Name("persons")
this.id
  |  |
  |  └ IdentifierValue::Name("id")
  |
  └ IdentifierValue::This

Fields

values: Vec<IdentifierValue>

List of identifier values (components)

Implementations

Creates new identifier

Arguments
  • values - List of identifier values (components)

Check if an identifier is canonical

An identifier is considered as canonical if none relative identifier values (IdentifierValue::This, IdentifierValue::Super) are present.

It affects (checks) nested identifiers as well.

Examples

Canonical identifiers.

use balena_temen::ast::*;

let identifier: Identifier = "names.wifi".parse().unwrap();
assert!(identifier.is_canonical());

let identifier: Identifier = "names.wifi[first].id".parse().unwrap();
assert!(identifier.is_canonical());

Not canonical identifiers.

use balena_temen::ast::*;

let identifier: Identifier = "names.this".parse().unwrap();
assert!(!identifier.is_canonical());

let identifier: Identifier = "names[this.index]".parse().unwrap();
assert!(!identifier.is_canonical());

Returns the canonical, absolute, identifier with all intermediate components normalized and nested identifiers canonicalized.

Nested identifiers (IdentifierValue::Identifier) are canonicalized too.

Arguments
  • position - An identifier position
Examples
use balena_temen::ast::*;

let identifier: Identifier = "names".parse().unwrap();
assert_eq!(identifier.canonicalize(&Identifier::default()).unwrap(), identifier);

let identifier: Identifier = "names.this.id.this.super".parse().unwrap();
let canonicalized: Identifier = "names".parse().unwrap();
assert_eq!(identifier.canonicalize(&Identifier::default()).unwrap(), canonicalized);

let identifier: Identifier = "super.id".parse().unwrap();
let position: Identifier = "wifi[`zrzka`].ssid".parse().unwrap();
let canonicalized: Identifier = "wifi[`zrzka`].id".parse().unwrap();
assert_eq!(identifier.canonicalize(&position).unwrap(), canonicalized);

Appends IdentifierValue::Name to the identifier

Arguments
  • name - A name (object field, string index)
Examples
use balena_temen::ast::*;

let identifier = Identifier::default()
    .name("wifi")
    .name("ssid");

let parsed = "wifi.ssid".parse().unwrap();

assert_eq!(identifier, parsed);

Appends IdentifierValue::Index to the identifier

Arguments
  • index - An array index
use balena_temen::ast::*;

let identifier = Identifier::default()
    .name("networks")
    .index(0);

let parsed = "networks[0]".parse().unwrap();

assert_eq!(identifier, parsed);

Appends IdentifierValue::Identifier to the identifier

Arguments
  • identifier - An identifier index
use balena_temen::ast::*;

let identifier = Identifier::default()
    .name("wifi")
    .identifier(Identifier::default().name("first_wifi_id"));

let parsed = "wifi[first_wifi_id]".parse().unwrap();

assert_eq!(identifier, parsed);

Returns Identifier with the last identifier value removed

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Creates new, empty, identifier

This identifier can be used to refer to the root.

The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.