Skip to main content

Var

Struct Var 

Source
pub struct Var<'a, S: VarScheme + ?Sized> { /* private fields */ }
Expand description

One variable of a VarScheme, which is to say a scheme together with an index.

It is returned by VarScheme::var, and it is what a variable’s name is written from: it implements Display, ToLatex, and ToTypst.

Implementations§

Source§

impl<'a, S: VarScheme + ?Sized> Var<'a, S>

Source

pub const fn new(scheme: &'a S, index: usize) -> Self

Makes a handle to one of a scheme’s variables.

VarScheme::var is the shorter way to say this, and works whenever the scheme’s type is known. This one also works for a scheme behind a dyn.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::vars::abc::AbcVars;
use malachite_base::vars::{Var, VarScheme};

let scheme: &dyn VarScheme = &AbcVars;
assert_eq!(Var::new(scheme, 2).to_string(), "c");
Source

pub const fn index(&self) -> usize

The variable’s index.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::vars::VarScheme;
use malachite_base::vars::xyz::XyzVars;

assert_eq!(XyzVars.var(3).index(), 3);
Source

pub const fn scheme(&self) -> &'a S

The scheme the variable belongs to.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::vars::VarScheme;
use malachite_base::vars::abc::AbcVars;

assert_eq!(AbcVars.var(3).scheme().capacity(), Some(26));

Trait Implementations§

Source§

impl<S: VarScheme + ?Sized> Clone for Var<'_, S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: VarScheme + ?Sized> Copy for Var<'_, S>

Source§

impl<S: VarScheme + ?Sized> Debug for Var<'_, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a variable to a String.

This is the same as the Display implementation: a variable is its name, and a scheme is not required to have a depiction of its own.

§Worst-case complexity

Same as the time and additional memory complexity of fmt_var for the scheme.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_base::vars::VarScheme;
use malachite_base::vars::indexed::IndexedVars;

assert_eq!(IndexedVars.var(10).to_debug_string(), "x₁₀");
Source§

impl<S: VarScheme + ?Sized> Display for Var<'_, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Converts a variable to a String.

This is the plain name, the one VarScheme::parse_var reads back.

§Worst-case complexity

Same as the time and additional memory complexity of fmt_var for the scheme.

§Examples
use malachite_base::vars::VarScheme;
use malachite_base::vars::indexed::IndexedVars;

assert_eq!(IndexedVars.var(10).to_string(), "x₁₀");
Source§

impl<S: VarScheme + ?Sized> ToLatex for Var<'_, S>

Source§

fn fmt_latex(&self, f: &mut Formatter<'_>) -> Result

Writes a variable as a LaTeX math-mode fragment.

§Worst-case complexity

Same as the time and additional memory complexity of fmt_var_latex for the scheme.

§Examples
use malachite_base::strings::latex::ToLatex;
use malachite_base::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;

assert_eq!(IndexedVars.var(10).to_latex_string(), "x_{10}");
assert_eq!(GreekVars.var(0).to_latex_string(), r"\alpha");

Those fragments render as $x_{10}$ and $\alpha$.

Source§

fn to_latex(&self) -> LatexWrapper<'_, Self>
where Self: Sized,

Converts a value to a LaTeX math-mode fragment. Read more
Source§

fn to_latex_string(&self) -> String
where Self: Sized,

Converts a value to a LaTeX math-mode fragment, as a String. Read more
Source§

impl<S: VarScheme + ?Sized> ToTypst for Var<'_, S>

Source§

fn fmt_typst(&self, f: &mut Formatter<'_>) -> Result

Writes a variable as a Typst math-mode fragment.

§Worst-case complexity

Same as the time and additional memory complexity of fmt_var_typst for the scheme.

§Examples
use malachite_base::strings::typst::ToTypst;
use malachite_base::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;

assert_eq!(IndexedVars.var(10).to_typst_string(), "x_(10)");
assert_eq!(GreekVars.var(0).to_typst_string(), "α");
Source§

fn to_typst(&self) -> TypstWrapper<'_, Self>
where Self: Sized,

Converts a value to a Typst math-mode fragment. Read more
Source§

fn to_typst_string(&self) -> String
where Self: Sized,

Converts a value to a Typst math-mode fragment, as a String. Read more

Auto Trait Implementations§

§

impl<'a, S> Freeze for Var<'a, S>
where &'a S: Freeze, S: ?Sized,

§

impl<'a, S> RefUnwindSafe for Var<'a, S>

§

impl<'a, S> Send for Var<'a, S>
where &'a S: Send, S: ?Sized,

§

impl<'a, S> Sync for Var<'a, S>
where &'a S: Sync, S: ?Sized,

§

impl<'a, S> Unpin for Var<'a, S>
where &'a S: Unpin, S: ?Sized,

§

impl<'a, S> UnsafeUnpin for Var<'a, S>
where &'a S: UnsafeUnpin, S: ?Sized,

§

impl<'a, S> UnwindSafe for Var<'a, S>
where &'a S: UnwindSafe, S: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U