Struct Pkl

Source
pub struct Pkl<'a> { /* private fields */ }
Expand description

The Pkl struct represents the main interface for working with PKL data.

Implementations§

Source§

impl<'a> Pkl<'a>

Source

pub fn new() -> Self

Creates a new, empty Pkl instance.

Source

pub fn parse(&mut self, source: &'a str) -> PklResult<()>

Parses a PKL source string and populates the internal context.

§Arguments
  • source - The PKL source string to parse.
§Returns

A PklResult indicating success or failure.

Source

pub fn generate_ast( &mut self, source: &'a str, ) -> PklResult<Vec<PklStatement<'a>>>

Generates an AST from a PKL source string.

§Arguments
  • source - The PKL source string to parse.
§Returns

A PklResult containing the generated AST or an error message.

Source

pub fn get(&self, name: &'a str) -> Option<&PklValue<'a>>

Retrieves a value from the context by name.

§Arguments
  • name - The name of the variable to retrieve.
§Returns

An Option containing a reference to the PklValue associated with the name, or None if the variable is not found.

Source

pub fn set( &mut self, name: &'a str, value: PklValue<'a>, ) -> Option<PklValue<'a>>

Sets or modifies a value in the context by name.

§Arguments
  • name - The name of the variable to set.
  • value - The value to set.
§Returns

An Option containing the previous value associated with the name, if any.

Source

pub fn remove(&mut self, name: &'a str) -> Option<PklValue<'a>>

Removes a value from the context by name.

§Arguments
  • name - The name of the variable to remove.
§Returns

An Option containing the removed value, if any.

Source

pub fn get_bool(&self, name: &'a str) -> PklResult<bool>

Retrieves a boolean value from the context.

§Arguments
  • name - The name of the variable to retrieve.
§Returns

A PklResult containing the boolean value or an error message if not found or wrong type.

Source

pub fn get_int(&self, name: &'a str) -> PklResult<i64>

Retrieves an integer value from the context.

§Arguments
  • name - The name of the variable to retrieve.
§Returns

A PklResult containing the integer value or an error message if not found or wrong type.

Source

pub fn get_float(&self, name: &'a str) -> PklResult<f64>

Retrieves a floating-point value from the context.

§Arguments
  • name - The name of the variable to retrieve.
§Returns

A PklResult containing the floating-point value or an error message if not found or wrong type.

Source

pub fn get_string(&self, name: &'a str) -> PklResult<&'a str>

Retrieves a string value from the context.

§Arguments
  • name - The name of the variable to retrieve.
§Returns

A PklResult containing the string value or an error message if not found or wrong type.

Source

pub fn get_object( &self, name: &'a str, ) -> PklResult<&HashMap<&'a str, PklValue<'a>>>

Retrieves an object value from the context.

§Arguments
  • name - The name of the variable to retrieve.
§Returns

A PklResult containing the object value or an error message if not found or wrong type.

Trait Implementations§

Source§

impl<'a> Clone for Pkl<'a>

Source§

fn clone(&self) -> Pkl<'a>

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<'a> Debug for Pkl<'a>

Source§

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

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

impl<'a> PartialEq for Pkl<'a>

Source§

fn eq(&self, other: &Pkl<'a>) -> 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<'a> StructuralPartialEq for Pkl<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Pkl<'a>

§

impl<'a> RefUnwindSafe for Pkl<'a>

§

impl<'a> Send for Pkl<'a>

§

impl<'a> Sync for Pkl<'a>

§

impl<'a> Unpin for Pkl<'a>

§

impl<'a> UnwindSafe for Pkl<'a>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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.