Generalize string types to take as arguments

`asciidoctor_rs::parse` and `asciidoctor_rs::parsing::tokenizer::Tokenizer::new` will take the more generic string types as arguments.
pull/11/head
gemmaro 3 years ago
parent 5d829a1933
commit c2020b0d7f

@ -25,7 +25,7 @@ pub(crate) mod utils;
/// ```rust /// ```rust
/// let expression = asciimath_rs::parse("sin(2x) + 3".to_string()); /// let expression = asciimath_rs::parse("sin(2x) + 3".to_string());
/// ``` /// ```
pub fn parse(content: String) -> Expression { pub fn parse<S: AsRef<str>>(content: S) -> Expression {
let mut tokenizer = Tokenizer::new(content); let mut tokenizer = Tokenizer::new(content);
let tokens = tokenizer.parse(); let tokens = tokenizer.parse();
let mut tree_parser = TreeParser::new(tokens); let mut tree_parser = TreeParser::new(tokens);

@ -19,8 +19,8 @@ pub struct Tokenizer {
} }
impl Tokenizer { impl Tokenizer {
pub fn new(text: String) -> Self { pub fn new<S: AsRef<str>>(text: S) -> Self {
let mut chars = text.chars().collect::<Vec<char>>(); let mut chars = text.as_ref().chars().collect::<Vec<char>>();
chars.push('\n'); chars.push('\n');
Self { Self {
ctm: CharTapeMachine::new(chars), ctm: CharTapeMachine::new(chars),

Loading…
Cancel
Save