Struct kerbalobjects::ksm::sections::ArgumentSection
source · 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
impl ArgumentSection
sourcepub fn with_capacity(amount: usize) -> Self
pub fn with_capacity(amount: usize) -> Self
Creates a new empty ArgumentSection, with the provided pre-allocated size
sourcepub fn with_arguments_checked(
self,
iter: impl IntoIterator<Item = KOSValue>
) -> (Self, Vec<ArgIndex>)
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
sourcepub fn with_arguments_unchecked(
self,
iter: impl IntoIterator<Item = KOSValue>
) -> (Self, Vec<ArgIndex>)
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
sourcepub fn num_index_bytes(&self) -> IntSize
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.
sourcepub fn find(&self, value: &KOSValue) -> Option<ArgIndex>
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.
sourcepub fn add_checked(&mut self, value: KOSValue) -> ArgIndex
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.
sourcepub fn add(&mut self, argument: KOSValue) -> ArgIndex
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.
sourcepub fn get(&self, index: ArgIndex) -> Option<&KOSValue>
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.
sourcepub fn arguments(&self) -> Iter<'_, KOSValue>
pub fn arguments(&self) -> Iter<'_, KOSValue>
Returns an iterator over all of the KOSValues that are stored in this section.
sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Returns the size in bytes that this section would take up in total in the final binary file.
sourcepub fn parse(
source: &mut BufferIterator<'_>
) -> Result<Self, ArgumentSectionParseError>
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.
Trait Implementations§
source§impl Clone for ArgumentSection
impl Clone for ArgumentSection
source§fn clone(&self) -> ArgumentSection
fn clone(&self) -> ArgumentSection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more