pub enum EnvBindingStrength {
Weakest,
Sum,
Product,
Power,
Strongest,
}Expand description
Describes the context in which to print an algebraic expression. It is usually used to determine when to use parenthesis during printing.
§Example
struct CustomDisplay<'a>(&'a DensePolyRing<StaticRing<i64>>, &'a El<DensePolyRing<StaticRing<i64>>>, EnvBindingStrength);
impl<'a> std::fmt::Display for CustomDisplay<'a> {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.get_ring().dbg_within(self.1, formatter, self.2)
}
}
let poly_ring = DensePolyRing::new(StaticRing::<i64>::RING, "X");
let f = poly_ring.add(poly_ring.one(), poly_ring.indeterminate());
assert_eq!("X + 1", format!("{}", CustomDisplay(&poly_ring, &f, EnvBindingStrength::Weakest)));
assert_eq!("X + 1", format!("{}", CustomDisplay(&poly_ring, &f, EnvBindingStrength::Sum)));
assert_eq!("(X + 1)", format!("{}", CustomDisplay(&poly_ring, &f, EnvBindingStrength::Product)));
assert_eq!("(X + 1)", format!("{}", CustomDisplay(&poly_ring, &f, EnvBindingStrength::Power)));
assert_eq!("(X + 1)", format!("{}", CustomDisplay(&poly_ring, &f, EnvBindingStrength::Strongest)));Variants§
Weakest
The weakest possible binding strength, i.e. never add parenthesis.
Sum
Binding strength of addition (and subtraction), i.e. only add parenthesis
if the expression includes an operation that binds weaker than + (I cannot
think of any example, this seems to be a rare situation).
Product
Binding strength of multiplication (and division), i.e. only add parenthesis if
the expression includes an operation that binds weaker than * (Standard example
would be +).
Power
Binding strength of powering, i.e. only add parenthesis if the expression
includes an operation that binds weaker than exponentiation (Standard examples would
be + or *).
Strongest
The strongest possible binding strength, i.e. always add parenthesis.
Trait Implementations§
Source§impl Clone for EnvBindingStrength
impl Clone for EnvBindingStrength
Source§fn clone(&self) -> EnvBindingStrength
fn clone(&self) -> EnvBindingStrength
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EnvBindingStrength
impl Debug for EnvBindingStrength
Source§impl Ord for EnvBindingStrength
impl Ord for EnvBindingStrength
Source§fn cmp(&self, other: &EnvBindingStrength) -> Ordering
fn cmp(&self, other: &EnvBindingStrength) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for EnvBindingStrength
impl PartialEq for EnvBindingStrength
Source§impl PartialOrd for EnvBindingStrength
impl PartialOrd for EnvBindingStrength
impl Copy for EnvBindingStrength
impl Eq for EnvBindingStrength
impl StructuralPartialEq for EnvBindingStrength
Auto Trait Implementations§
impl Freeze for EnvBindingStrength
impl RefUnwindSafe for EnvBindingStrength
impl Send for EnvBindingStrength
impl Sync for EnvBindingStrength
impl Unpin for EnvBindingStrength
impl UnwindSafe for EnvBindingStrength
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more