Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Config

§Examples

let input = String::from("
#define bar 42

foo = bar;
");

let config = Config::from_string(input, None, &Vec::new(), &mut Warnings::new()).expect("Failed to parse config");

assert_eq!("foo = 42;\n", config.to_string().unwrap());
assert_eq!(b"\0raP", &config.to_cursor().unwrap().into_inner()[..4]);

Implementations§

Source§

impl Config

Source

pub fn root(&self) -> &ConfigClass

The unnamed top-level class holding all entries of the file.

Source

pub fn enum_values(&self) -> &[(String, i32)]

The values of the enum { ... } blocks, in source order (or table order for a rapified config).

Names are lowercase, as the game stores them. The values of all blocks, at any class level, land in this one table.

Source

pub fn write<O: Write>(&self, output: &mut O) -> Result<(), Error>

Writes the config (unrapified) to the output.

§Errors

Returns an error on I/O failure.

Source

pub fn write_with<O: Write>( &self, output: &mut O, options: &WriteOptions, ) -> Result<(), Error>

Writes the config (unrapified) to the output with the given options.

§Errors

Returns an error on I/O failure or if a name cannot be written as text.

Source

pub fn to_string(&self) -> Result<String, Error>

Returns the unrapified config as a string.

§Errors

Returns an error on I/O failure or invalid UTF-8 in the output.

Source

pub fn write_rapified<O: Write>(&self, output: &mut O) -> Result<(), Error>

Writes the rapified config to the output.

§Errors

Returns an error on I/O failure or if the config cannot be rapified.

Source

pub fn to_cursor(&self) -> Result<Cursor<Box<[u8]>>, Error>

Returns the rapified config as a Cursor.

§Errors

Returns an error if the config cannot be rapified.

Source

pub fn read<I: Read>( input: &mut I, path: Option<PathBuf>, includefolders: &[PathBuf], warnings: &mut dyn WarningSink, ) -> Result<Config, Error>

Reads the unrapified config from input, preprocessing it.

path is the path to the input if it is known and is used for relative includes and error messages. includefolders are the folders searched recursively for absolute includes.

§Errors

Returns an error on preprocessing or parse failures.

Source

pub fn read_in<I: Read>( input: &mut I, path: Option<PathBuf>, includefolders: &IncludeFolders, warnings: &mut dyn WarningSink, ) -> Result<Config, Error>

Like Config::read, with the include folders given as an IncludeFolders (some of them can be checked directly instead of searched recursively).

§Errors

Returns an error on preprocessing or parse failures.

Source

pub fn from_string( input: String, path: Option<PathBuf>, includefolders: &[PathBuf], warnings: &mut dyn WarningSink, ) -> Result<Config, Error>

Preprocesses and parses input string.

path is the path to the input if it is known and is used for relative includes and error messages. includefolders are the folders searched recursively for absolute includes.

§Errors

Returns an error on preprocessing or parse failures.

Source

pub fn from_string_in( input: String, path: Option<PathBuf>, includefolders: &IncludeFolders, warnings: &mut dyn WarningSink, ) -> Result<Config, Error>

Like Config::from_string, with the include folders given as an IncludeFolders.

§Errors

Returns an error on preprocessing or parse failures.

Source

pub fn read_rapified<I: Read + Seek>(input: &mut I) -> Result<Config, Error>

Reads the rapified config from input.

§Errors

Returns an error if the input is not a rapified config or cannot be parsed.

Trait Implementations§

Source§

impl Debug for Config

Source§

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

Formats the value using the given formatter. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.