pub struct Include(/* private fields */);Expand description
An AST node for $ast
Implementations§
Source§impl Include
impl Include
Sourcepub fn is_optional(&self) -> bool
pub fn is_optional(&self) -> bool
Check if this is an optional include (-include or sinclude)
Sourcepub fn parent(&self) -> Option<MakefileItem>
pub fn parent(&self) -> Option<MakefileItem>
Get the parent item of this include directive, if any
Returns Some(MakefileItem) if this include 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
include debug.mk
endif
"#.parse().unwrap();
let cond = makefile.conditionals().next().unwrap();
let inc = cond.if_items().next().unwrap();
// Include's parent is the conditional
assert!(matches!(inc, makefile_lossless::MakefileItem::Include(_)));Sourcepub fn remove(&mut self) -> Result<(), Error>
pub fn remove(&mut self) -> Result<(), Error>
Remove this include directive from the makefile
This will also remove any preceding comments.
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "include config.mk\nVAR = value\n".parse().unwrap();
let mut inc = makefile.includes().next().unwrap();
inc.remove().unwrap();
assert_eq!(makefile.includes().count(), 0);Sourcepub fn set_path(&mut self, new_path: &str)
pub fn set_path(&mut self, new_path: &str)
Set the path of this include directive
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "include old.mk\n".parse().unwrap();
let mut inc = makefile.includes().next().unwrap();
inc.set_path("new.mk");
assert_eq!(inc.path(), Some("new.mk".to_string()));
assert_eq!(makefile.to_string(), "include new.mk\n");Sourcepub fn set_optional(&mut self, optional: bool)
pub fn set_optional(&mut self, optional: bool)
Make this include optional (change “include” to “-include”)
If the include is already optional, this has no effect.
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "include config.mk\n".parse().unwrap();
let mut inc = makefile.includes().next().unwrap();
inc.set_optional(true);
assert!(inc.is_optional());
assert_eq!(makefile.to_string(), "-include config.mk\n");Trait Implementations§
impl Eq for Include
impl StructuralPartialEq for Include
Auto Trait Implementations§
impl Freeze for Include
impl !RefUnwindSafe for Include
impl !Send for Include
impl !Sync for Include
impl Unpin for Include
impl !UnwindSafe for Include
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
Mutably borrows from an owned value. Read more
§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)
🔬This is a nightly-only experimental API. (
clone_to_uninit)