pub struct TextFSM {
pub parser: TextFSMParser,
pub curr_state: String,
pub curr_record: DataRecord,
pub filldown_record: DataRecord,
pub records: VecDeque<DataRecord>,
}Expand description
The runtime engine for TextFSM parsing.
Fields§
§parser: TextFSMParserThe underlying compiled parser.
curr_state: StringThe current state of the engine.
curr_record: DataRecordThe record currently being populated.
filldown_record: DataRecordRecord containing values to be ‘filled down’ to subsequent records.
records: VecDeque<DataRecord>List of all successfully parsed records.
Implementations§
Source§impl TextFSM
impl TextFSM
Sourcepub fn from_string(content: &str) -> Result<Self>
pub fn from_string(content: &str) -> Result<Self>
Creates a new TextFSM instance from a template string.
Sourcepub fn from_file<P: AsRef<Path>>(fname: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(fname: P) -> Result<Self>
Creates a new TextFSM instance from a template file.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the engine to its initial state, clearing all records and resetting variables. This allows reusing the parsed template for a new file.
Sourcepub fn set_curr_state(&mut self, state_name: &str) -> Result<()>
pub fn set_curr_state(&mut self, state_name: &str) -> Result<()>
Sets the current state of the engine.
pub fn is_key_value(&self, value_name: &str) -> Option<bool>
pub fn is_filldown_value(&self, value_name: &str) -> Option<bool>
pub fn is_fillup_value(&self, value_name: &str) -> Option<bool>
pub fn is_list_value(&self, value_name: &str) -> Option<bool>
Sourcepub fn insert_value_optimized(
&self,
curr_record: &mut DataRecord,
filldown_record: &mut DataRecord,
var_info: &CapturedVariable,
maybe_value: Option<&str>,
aline: &str,
) -> Result<()>
pub fn insert_value_optimized( &self, curr_record: &mut DataRecord, filldown_record: &mut DataRecord, var_info: &CapturedVariable, maybe_value: Option<&str>, aline: &str, ) -> Result<()>
Optimized value insertion into records.
Sourcepub fn parse_line(&mut self, aline: &str) -> Result<ParseStatus>
pub fn parse_line(&mut self, aline: &str) -> Result<ParseStatus>
Processes a single line of input against the current state’s rules.
Sourcepub fn lowercase_keys(src: &VecDeque<DataRecord>) -> Vec<DataRecord>
pub fn lowercase_keys(src: &VecDeque<DataRecord>) -> Vec<DataRecord>
Returns a new vector of records with all field names converted to lowercase.
Sourcepub fn parse_reader<R: BufRead>(self, reader: R) -> TextFsmIter<R> ⓘ
pub fn parse_reader<R: BufRead>(self, reader: R) -> TextFsmIter<R> ⓘ
Parses input from a reader line-by-line using an iterator. This is memory efficient for large files as it doesn’t buffer all records.
§Arguments
reader- A type implementingBufRead(e.g.,BufReader<File>).
Sourcepub fn parse_string(
&mut self,
input: &str,
conversion: Option<DataRecordConversion>,
) -> Result<Vec<DataRecord>>
pub fn parse_string( &mut self, input: &str, conversion: Option<DataRecordConversion>, ) -> Result<Vec<DataRecord>>
Parses input from a string.
§Arguments
input- The input string to parse.conversion- Optional transformation to apply to the results.
Sourcepub fn parse_file<P: AsRef<Path>>(
&mut self,
fname: P,
conversion: Option<DataRecordConversion>,
) -> Result<Vec<DataRecord>>
pub fn parse_file<P: AsRef<Path>>( &mut self, fname: P, conversion: Option<DataRecordConversion>, ) -> Result<Vec<DataRecord>>
Parses an entire file and returns the extracted records.
§Arguments
fname- Path to the data file to parse.conversion- Optional transformation to apply to the results.