pub struct VariableDefinition(/* private fields */);Expand description
An AST node for $ast
Implementations§
Source§impl VariableDefinition
impl VariableDefinition
Sourcepub fn assignment_operator(&self) -> Option<String>
pub fn assignment_operator(&self) -> Option<String>
Get the assignment operator/flavor used in this variable definition
Returns the operator as a string: “=”, “:=”, “::=”, “:::=”, “+=”, “?=”, or “!=”
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "VAR := value\n".parse().unwrap();
let var = makefile.variable_definitions().next().unwrap();
assert_eq!(var.assignment_operator(), Some(":=".to_string()));Sourcepub fn parent(&self) -> Option<MakefileItem>
pub fn parent(&self) -> Option<MakefileItem>
Get the parent item of this variable definition, if any
Returns Some(MakefileItem) if this variable has a parent that is a MakefileItem
(e.g., a Conditional), or None if the parent is the root Makefile node.
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = r#"ifdef DEBUG
VAR = value
endif
"#.parse().unwrap();
let cond = makefile.conditionals().next().unwrap();
let var = cond.if_items().next().unwrap();
// Variable's parent is the conditional
assert!(matches!(var, makefile_lossless::MakefileItem::Variable(_)));Sourcepub fn remove(&mut self)
pub fn remove(&mut self)
Remove this variable definition from its parent makefile
This will also remove any preceding comments and up to 1 empty line before the variable.
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "VAR = value\n".parse().unwrap();
let mut var = makefile.variable_definitions().next().unwrap();
var.remove();
assert_eq!(makefile.variable_definitions().count(), 0);Sourcepub fn set_assignment_operator(&mut self, op: &str)
pub fn set_assignment_operator(&mut self, op: &str)
Change the assignment operator of this variable definition while preserving everything else (export prefix, variable name, value, whitespace, etc.)
§Arguments
op- The new operator: “=”, “:=”, “::=”, “:::=”, “+=”, “?=”, or “!=”
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "VAR := value\n".parse().unwrap();
let mut var = makefile.variable_definitions().next().unwrap();
var.set_assignment_operator("?=");
assert_eq!(var.assignment_operator(), Some("?=".to_string()));
assert!(makefile.code().contains("VAR ?= value"));Sourcepub fn set_value(&mut self, new_value: &str)
pub fn set_value(&mut self, new_value: &str)
Update the value of this variable definition while preserving the rest (export prefix, operator, whitespace, etc.)
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "export VAR := old_value\n".parse().unwrap();
let mut var = makefile.variable_definitions().next().unwrap();
var.set_value("new_value");
assert_eq!(var.raw_value(), Some("new_value".to_string()));
assert!(makefile.code().contains("export VAR := new_value"));Trait Implementations§
Source§impl AstNode for VariableDefinition
impl AstNode for VariableDefinition
Source§impl Clone for VariableDefinition
impl Clone for VariableDefinition
Source§fn clone(&self) -> VariableDefinition
fn clone(&self) -> VariableDefinition
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Display for VariableDefinition
impl Display for VariableDefinition
Source§impl Hash for VariableDefinition
impl Hash for VariableDefinition
Source§impl PartialEq for VariableDefinition
impl PartialEq for VariableDefinition
impl Eq for VariableDefinition
impl StructuralPartialEq for VariableDefinition
Auto Trait Implementations§
impl Freeze for VariableDefinition
impl !RefUnwindSafe for VariableDefinition
impl !Send for VariableDefinition
impl !Sync for VariableDefinition
impl Unpin for VariableDefinition
impl !UnwindSafe for VariableDefinition
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)