Struct physical_quantity::unit::Parser
source · [−]pub struct Parser<K, T> where
K: AsRef<str>,
T: AsRef<[(K, (Conv, DynDim))]>, { /* private fields */ }
Expand description
Unit string parser.
Syntax of unit string
You can write unit string as you always write it.
Syntax
Unit :
Compound ([
Modifier]
)?Modifier :
abs
|dif
|gage
Compound :
Product ( Slash Delimiter* Product )?Slash :
/
|÷
\u{00F7}
|⁄
\u{2044}
|∕
\u{2215}
|⟋
\u{27CB}
|⧸
\u{29F8}
|毎
\u{6BCE}}
Delimiter :
WhiteSpace1 | ZeroWidthSpace2 |*
|·
\u{00B7}
|×
\u{00D7}
|•
\u{2022}
|∙
\u{2219}
|⋅
\u{22C5}
|✕
\u{2715}
|✖
\u{2716}
|・
\u{30FB}
|・
\u{FF65}
Product :
( Element Delimiter* )+Element :
Term Exponent?Exponent :
-
? [0
-9
]+
The unit string is divided into numerator and denominator by Slash. The denominator is optional. The numerator and denominator are composed as a product of Element s. Each Element s in the product need to be delimited explicitly. Each Element s are composed of Name with SI Prefix and Exponent. SI Prefix and Exponent are optional.
Name
Name consists of any Unicode char except the followings.
- chars composing Delimiter.
- chars composing Slash.
- chars composing Exponent.
- parentheses
[
]
(
)
{
}
<
>
Square brackets mark up Modifier. Any other parentheses have no meanings in this syntax. So, these parentheses should not appear in the unit string.
Parser looks up this Name in the array set to tbl
member.
Prefix
Even if it is not an SI unit, any Name may be promoted to Term with an Prefix.
In addition to the formal SI prefix, following CJK-compatible characters with the same meaning can be used for the prefix.
㌐
\u{3310}
: giga (G
)㍋
\u{334B}
: mega (M
)㌔
\u{3314}
: kilo (k
)㍲
\u{3372}
: deca (da
)㌥
\u{3325}
: deci (d
)㌢
\u{3322}
: centi (c
)㍉
\u{3349}
: milli (m
)μ
\u{00B5}
,μ
\u{03BC}
,㍃
\u{3343}
: micro㌨
\u{3328}
: nano (n
)㌰
\u{3330}
: pico (p
)
Term
Whether Name has Prefix or not is first parsed as if it has a Prefix.
For example, when the foot (ft) and ton (t) defined the definition table,
ft
matches femto ton (same as nano gram (ng
))!!
Therefore, the foot is defined as ft.
in the default definition.
The period can compose of Name.
Modifier
Ummm…
char which char::is_whitespace() returns true. ↩
\u{200B}
,\u{200C}
,\u{200D}
↩
Implementations
Auto Trait Implementations
impl<K, T> RefUnwindSafe for Parser<K, T> where
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<K, T> Send for Parser<K, T> where
K: Send,
T: Send,
impl<K, T> Sync for Parser<K, T> where
K: Sync,
T: Sync,
impl<K, T> Unpin for Parser<K, T> where
K: Unpin,
T: Unpin,
impl<K, T> UnwindSafe for Parser<K, T> where
K: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more