Struct uclicious::raw::parser::Parser

source ·
pub struct Parser { /* private fields */ }
Expand description

Raw parser object.

Implementations§

source§

impl Parser

source

pub fn with_flags(flags: ParserFlags) -> Self

Create a new parser with given option flags.

source

pub fn add_chunk_full<C: AsRef<str>>( &mut self, chunk: C, priority: Priority, strategy: DuplicateStrategy ) -> Result<(), UclError>

Add a chunk of text to the parser. String must:

  • not have \0 character;
  • must be valid UCL object;
source

pub fn add_file_full<F: AsRef<Path>>( &mut self, file: F, priority: Priority, strategy: DuplicateStrategy ) -> Result<(), UclError>

Add a file by a file path to the parser. This function uses mmap call to load file, therefore, it should not be shrunk during parsing.

source

pub fn add_fd_full<F: AsRawFd>( &mut self, fd: F, priority: Priority, strategy: DuplicateStrategy ) -> Result<(), UclError>

source

pub fn set_filevars<F: AsRef<Path>>( &mut self, filename: F, need_expand: bool ) -> Result<(), UclError>

Add the standard file variables to the parser based on the filename specified:

  • $FILENAME- a filename of ucl input
  • $CURDIR - a current directory of the input

For example, if a filename param is ../something.conf then the variables will have the following values:

  • $FILENAME - ../something.conf
  • $CURDIR - ..

if need_expand parameter is true then all relative paths are expanded using realpath call. In this example if .. is /etc/dir then variables will have these values:

  • $FILENAME - /etc/something.conf
  • $CURDIR - /etc
source

pub fn get_object(&mut self) -> Result<Object, UclError>

Get a top object for a parser.

source

pub fn register_variable<K: AsRef<str>, V: AsRef<str>>( &mut self, var: K, value: V ) -> &mut Self

Register new variable $var that should be replaced by the parser to the value string. Variables need to be registered before they are referenced.

Panics

This function panics if either var or value has \0.

source

pub unsafe fn set_variables_handler_raw( &mut self, handler: ucl_variable_handler, ud: *mut c_void ) -> &mut Self

Register function as an unknown variable handler. Parser can only have one handler.

  • handler - a function pointer
  • ud - an opaque pointer that will be passed to a handler
Safety

Both object behind ud and function behind handler need to live at least as long as the parser.

source

pub fn set_variables_handler( &mut self, handler: Box<dyn VariableHandler> ) -> &mut Self

A safe counterpart of Parser::set_variable_handler_raw. Unlike unsafe version this one takes ownership of a handler and ensures it stays alive as long as parser does.

Caveats

Parser can have only bar handler. In order to have multiple, please use CompoundHandler to join multiple handlers into one.

Trait Implementations§

source§

impl Debug for Parser

source§

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

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

impl Default for Parser

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for Parser

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Parser

§

impl !Send for Parser

§

impl !Sync for Parser

§

impl Unpin for Parser

§

impl !UnwindSafe for Parser

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: FromObject<T>,

source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.