Struct TwoDA

Source
pub struct TwoDA {
    pub file_type: FixedSizeString<4>,
    pub file_version: FixedSizeString<4>,
    pub default_value: Option<String>,
    /* private fields */
}
Expand description

2DA table file

Fields§

§file_type: FixedSizeString<4>

File type (2DA)

§file_version: FixedSizeString<4>

File version

§default_value: Option<String>

Implementations§

Source§

impl TwoDA

Source

pub fn from_str( input: &str, repair: bool, ) -> IResult<&str, Self, VerboseError<&str>>

Parse 2DA data an input str

§Args:
  • input: data to parse
  • repair: true to repair inconsistent 2DA data (bad column count, row indices, …)
Source

pub fn to_string(&self, compact: bool) -> String

Serializes the 2DA table

§Args:
  • compact: true will generate minified 2DA data. NWN2 will be able to parse this table, but this parser will require repair=true to be set when parsing
Source

pub fn get_columns(&self) -> &Vec<String>

Returns the columns list

Source

pub fn len_cols(&self) -> usize

Returns the number of columns

Source

pub fn len_rows(&self) -> usize

Returns the number of rows

Source

pub fn resize_rows(&mut self, len: usize)

Resize the 2DA table to be able to contain len rows

Source

pub fn get_row(&self, row: usize) -> Option<&[Option<String>]>

Returns a row as a list of 2DA fields

Source

pub fn get_row_mut(&mut self, row: usize) -> Option<&mut [Option<String>]>

Returns a row as a list of 2DA fields

Source

pub fn get_row_col(&self, row: usize, column: usize) -> &Option<String>

Returns a field using its row index and column index

Source

pub fn get_row_label(&self, row: usize, label: &str) -> &Option<String>

Returns a field using its row index and column name. Column names are case-insensitive

Source

pub fn field_encoded_len<S: AsRef<str>>(field: &Option<S>) -> usize

Returns the length of a 2DA field when encoded (using quotes and escape sequences when needed)

Source

pub fn encode_field<S: AsRef<str>>(field: &Option<S>) -> String

Encode a 2DA field, adding quotes when needed, and returns the resulting string

Source

pub fn parse_row( input: &str, ) -> IResult<&str, Vec<Option<String>>, VerboseError<&str>>

Parses a 2DA row returning a list of fields (including the row index number)

Source

pub fn encode_row<S: AsRef<str>>( row_index: usize, row_data: &[Option<S>], column_sizes: Option<&[usize]>, compact: bool, ) -> String

Serializes a row to string

§Args:
  • row_index: Row index number
  • row_data: List of row fields (without the row index)
  • column_sizes: If Some, the sizes will be used for padding the different fields, to align multiple columns together
  • compact: true to minify the row by removing empty trailing fields. Note: column_sizes is used even if compact is true
Source

pub fn encode_rows<S1: AsRef<str>, S2: AsRef<str>>( rows: &[(usize, &[Option<S1>])], columns: Option<&[S2]>, compact: bool, ) -> String

Serializes a list of row to string

§Args:
  • rows: List of tuples containing the row index + fields list
  • columns: If Some, adds the columns list atop if the rows
  • compact: true to minify the output by not aligning columns and removing trailing empty fields
Source

pub fn iter(&self) -> Chunks<'_, Option<String>>

Returns an iterator over each 2DA row

Source

pub fn is_merge(&self) -> bool

Returns true if the 2DA is meant to be merged (2DAM file type)

Source

pub fn get_row_merge_actions(&self, row_index: usize) -> Option<&[MergeAction]>

Returns the merge mask for the given row, if set. Only useful if it was parsed as a 2DAM file

Trait Implementations§

Source§

impl Clone for TwoDA

Source§

fn clone(&self) -> TwoDA

Returns a duplicate 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 Debug for TwoDA

Source§

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

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

impl<'de> Deserialize<'de> for TwoDA

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TwoDA

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for TwoDA

§

impl RefUnwindSafe for TwoDA

§

impl Send for TwoDA

§

impl Sync for TwoDA

§

impl Unpin for TwoDA

§

impl UnwindSafe for TwoDA

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,