pub struct Amount(/* private fields */);Expand description
Units amount: [sign] (NUMBER | PAREN_EXPR) ([WS] op [WS] [sign] (NUMBER | PAREN_EXPR))* [WS CURRENCY], or a
bare CURRENCY. Phase 2.4 extension supports arithmetic.
Implementations§
Source§impl Amount
impl Amount
Sourcepub fn sign(&self) -> Option<Sign>
pub fn sign(&self) -> Option<Sign>
Sign token (MINUS or PLUS), if present as the FIRST
non-whitespace child of AMOUNT. Returns None if no
sign or if the leading non-whitespace token is something
else (e.g., L_PAREN, NUMBER, CURRENCY).
Sourcepub fn number(&self) -> Option<Number>
pub fn number(&self) -> Option<Number>
First NUMBER child token (the leading operand). For an
arithmetic expression like 10+5 USD, this is 10; for
a bare CURRENCY amount this is None.
Sourcepub fn currency(&self) -> Option<CurrencyName>
pub fn currency(&self) -> Option<CurrencyName>
The trailing currency at paren-depth 0.
For 100 USD, 100USD, (1+2) USD: returns the trailing
USD. For bare currency-only AMOUNT(CURRENCY): returns
the same token. For malformed (1 USD) (CURRENCY inside
parens, no outer trailing currency): returns None. For
unclosed (1 USD\n or stray-closer 1 USD) (unbalanced
parens): returns None, refusing to surface a possibly
paren-internal currency.
Single forward pass with paren-depth tracking; no
allocation. emit_amount_operand keeps paren contents
flat under AMOUNT (no PAREN_EXPR sub-node), so depth
tracking is the only structural disambiguator.
Sourcepub fn is_arithmetic(&self) -> bool
pub fn is_arithmetic(&self) -> bool
Returns true iff the amount contains an arithmetic operator
(+, - between operands, *, /) or a parenthesized
sub-expression — useful for typed-AST consumers that need
to defer to expression evaluation.
Trait Implementations§
Source§impl AstNode for Amount
impl AstNode for Amount
Source§fn can_cast(kind: SyntaxKind) -> bool
fn can_cast(kind: SyntaxKind) -> bool
kind is the wrapper’s expected node
kind. Used by cast and by enum dispatch.Source§fn cast(syntax: SyntaxNode) -> Option<Self>
fn cast(syntax: SyntaxNode) -> Option<Self>
syntax if its kind matches; otherwise None.Source§fn syntax(&self) -> &SyntaxNode
fn syntax(&self) -> &SyntaxNode
text() reproduces the original
bytes; children() / children_with_tokens() walk the
tree.impl Eq for Amount
impl StructuralPartialEq for Amount
Auto Trait Implementations§
impl !RefUnwindSafe for Amount
impl !Send for Amount
impl !Sync for Amount
impl !UnwindSafe for Amount
impl Freeze for Amount
impl Unpin for Amount
impl UnsafeUnpin for Amount
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.