pub struct ArgumentSection { /* private fields */ }
Expand description

An argument section within a KSM file.

You can create a new ArgumentSection using new() and then add items using add():

This section stores all operands of every instruction contained within the code sections of a KSM file, which all index into the file’s argument section.

use kerbalobjects::KOSValue;
use kerbalobjects::ksm::sections::ArgumentSection;

let mut arg_section = ArgumentSection::new();

let index = arg_section.add(KOSValue::Int16(2));

See the file format docs for more details.

Implementations§

source§

impl ArgumentSection

source

pub fn new() -> Self

Creates a new empty ArgumentSection

source

pub fn with_capacity(amount: usize) -> Self

Creates a new empty ArgumentSection, with the provided pre-allocated size

source

pub fn with_arguments_checked( self, iter: impl IntoIterator<Item = KOSValue> ) -> (Self, Vec<ArgIndex>)

A builder-style method that takes an iterator of KOSValues that should be added to this ArgumentSection

This variant performs checking as the items are added

This also returns a Vec that represent all of the indices that every element inserted resides at, and will contain duplicates if duplicate elements were added.

source

pub fn with_arguments_unchecked( self, iter: impl IntoIterator<Item = KOSValue> ) -> (Self, Vec<ArgIndex>)

A builder-style method that takes an iterator of KOSValues that should be added to this ArgumentSection

This variant does not perform checking as the items are added

This also returns a Vec that represent all of the indices that every element inserted resides at, and will not contain duplicates even if duplicate elements were added.

source

pub fn num_index_bytes(&self) -> IntSize

Returns the NumArgIndexBytes that this argument section currently requires.

This represents the current size range of this argument section, because this is the number of bytes that are required to reference an item within the argument section.

source

pub fn find(&self, value: &KOSValue) -> Option<ArgIndex>

Returns the ArgIndex into this argument section that a KOSValue resides at, or None if no such value is in this section.

source

pub fn add_checked(&mut self, value: KOSValue) -> ArgIndex

Add a new KOSValue to this argument section, checking if it is a duplicate, and returning the ArgIndex of the value. If it already exists, the ArgIndex of that value is returned, if it does not, then it is added, and the new ArgIndex is returned.

source

pub fn add(&mut self, argument: KOSValue) -> ArgIndex

Adds a new KOSValue to this argument section.

This does not do any sort of checking for duplication and will simply add it.

This function returns the ArgIndex that can be used to refer to the inserted value, for example when trying to reference it in an instruction.

source

pub fn get(&self, index: ArgIndex) -> Option<&KOSValue>

Gets a reference to a particular KOSValue in this argument section.

This is done using the ArgIndex that is returned when the value was added.

Returns None of the ArgIndex doesn’t refer to a valid value.

source

pub fn arguments(&self) -> Iter<'_, KOSValue>

Returns an iterator over all of the KOSValues that are stored in this section.

source

pub fn size_bytes(&self) -> usize

Returns the size in bytes that this section would take up in total in the final binary file.

source

pub fn parse( source: &mut BufferIterator<'_> ) -> Result<Self, ArgumentSectionParseError>

Attempts to parse an argument section from the current buffer iterator.

This can fail if the buffer runs out of bytes, or if the argument section is malformed.

source

pub fn write(&self, buf: &mut Vec<u8>)

Appends the byte representation of this argument section to a buffer of bytes

Trait Implementations§

source§

impl Clone for ArgumentSection

source§

fn clone(&self) -> ArgumentSection

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 Debug for ArgumentSection

source§

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

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

impl Default for ArgumentSection

source§

fn default() -> Self

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

Auto Trait Implementations§

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> ToOwned for Twhere T: Clone,

§

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 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: 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.