#[non_exhaustive]pub struct Directive<D> {
pub date: Date,
pub content: DirectiveContent<D>,
pub metadata: Map<D>,
pub line_number: u32,
}
Expand description
A beancount “directive”
It has fields common to all directives, and a Directive::content
field with
a different content for each directive type.
let input = r#"
2022-01-01 open Assets:Cash
2022-01-01 * "Grocery shopping"
Expenses:Groceries 10 CHF
Assets:Cash
"#;
let beancount: BeancountFile<f64> = input.parse().unwrap();
assert_eq!(beancount.directives.len(), 2);
for directive in beancount.directives {
println!("line: {}", directive.line_number);
println!("metadata: {:#?}", directive.metadata);
match directive.content {
DirectiveContent::Open(open) => println!("open account directive: {open:?}"),
DirectiveContent::Transaction(trx) => println!("transaction: {trx:?}"),
other => println!("unknown directive: {other:?}"),
}
}
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.date: Date
Date of the directive
content: DirectiveContent<D>
Content of the directive that is specific to each directive type
metadata: Map<D>
Metadata associated to the directive
See the metadata
module for more
line_number: u32
Line number where the directive was found in the input file
Trait Implementations§
impl<D> StructuralPartialEq for Directive<D>
Auto Trait Implementations§
impl<D> Freeze for Directive<D>where
D: Freeze,
impl<D> RefUnwindSafe for Directive<D>where
D: RefUnwindSafe,
impl<D> Send for Directive<D>where
D: Send,
impl<D> Sync for Directive<D>where
D: Sync,
impl<D> Unpin for Directive<D>where
D: Unpin,
impl<D> UnwindSafe for Directive<D>where
D: UnwindSafe,
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