pub struct Rule(/* private fields */);Expand description
An AST node for $ast
Implementations§
source§impl Rule
impl Rule
sourcepub fn targets(&self) -> impl Iterator<Item = String>
pub fn targets(&self) -> impl Iterator<Item = String>
Targets of this rule
§Example
use makefile_lossless::Rule;
let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
assert_eq!(rule.targets().collect::<Vec<_>>(), vec!["rule"]);sourcepub fn prerequisites(&self) -> impl Iterator<Item = String>
pub fn prerequisites(&self) -> impl Iterator<Item = String>
Get the prerequisites in the rule
§Example
use makefile_lossless::Rule;
let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
assert_eq!(rule.prerequisites().collect::<Vec<_>>(), vec!["dependency"]);sourcepub fn recipes(&self) -> impl Iterator<Item = String>
pub fn recipes(&self) -> impl Iterator<Item = String>
Get the commands in the rule
§Example
use makefile_lossless::Rule;
let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["command"]);sourcepub fn replace_command(&self, i: usize, line: &str)
pub fn replace_command(&self, i: usize, line: &str)
Replace the command at index i with a new line
§Example
use makefile_lossless::Rule;
let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
rule.replace_command(0, "new command");
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["new command"]);
assert_eq!(rule.to_string(), "rule: dependency\n\tnew command\n");sourcepub fn push_command(&self, line: &str)
pub fn push_command(&self, line: &str)
Add a new command to the rule
§Example
use makefile_lossless::Rule;
let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
rule.push_command("command2");
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["command", "command2"]);Trait Implementations§
source§impl AstNode for Rule
impl AstNode for Rule
type Language = Lang
fn can_cast(kind: SyntaxKind) -> bool
fn cast(syntax: SyntaxNode<Lang>) -> Option<Self>
fn syntax(&self) -> &SyntaxNode<Lang>
fn clone_for_update(&self) -> Selfwhere
Self: Sized,
fn clone_subtree(&self) -> Selfwhere
Self: Sized,
impl Eq for Rule
impl StructuralPartialEq for Rule
Auto Trait Implementations§
impl Freeze for Rule
impl !RefUnwindSafe for Rule
impl !Send for Rule
impl !Sync for Rule
impl Unpin for Rule
impl !UnwindSafe for Rule
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more