The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Read nom Input From Inside A Struct

TODO: Pull subtitle into page object
Code
//! ```cargo
//! [dependencies]
//! nom = "7.1.3"
//! ```

use nom::character::complete::alphanumeric1;
use nom::character::complete::space1;
use nom::multi::separated_list1;
use nom::IResult;

struct Parser {
  source: Option<String>
}

impl Parser {
  pub fn parse(&self) -> IResult<&str, Vec<&str>> {
    let (source, result) = separated_list1(
      space1, alphanumeric1
    )(self.source.as_ref().unwrap().as_str())?;
    Ok((source, result))
  }
}


fn main() {
  let source = "the quick brown fox".to_string();
  let p = Parser {
    source: Some(source)
  };
  dbg!(p.parse().unwrap().1);

}
Results
[neopolitan_code_run:32] p.parse().unwrap().1 = [
    "the",
    "quick",
    "brown",
    "fox",
]

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Read nom Input From Inside A Struct

-- code
-- rust

//! ```cargo
//! [dependencies]
//! nom = "7.1.3"
//! ```

use nom::character::complete::alphanumeric1;
use nom::character::complete::space1;
use nom::multi::separated_list1;
use nom::IResult;

struct Parser {
  source: Option<String>
}

impl Parser {
  pub fn parse(&self) -> IResult<&str, Vec<&str>> {
    let (source, result) = separated_list1(
      space1, alphanumeric1
    )(self.source.as_ref().unwrap().as_str())?;
    Ok((source, result))
  }
}


fn main() {
  let source = "the quick brown fox".to_string();
  let p = Parser {
    source: Some(source)
  };
  dbg!(p.parse().unwrap().1);

}

-- results/

[neopolitan_code_run:32] p.parse().unwrap().1 = [
    "the",
    "quick",
    "brown",
    "fox",
]

-- /results

-- categories
-- Rust 
-- nom

-- metadata
-- date: 2023-12-09 19:18:46
-- id: 2zkouqzw
-- site: aws
-- type: post
-- status: draft