Polynomial

Struct Polynomial 

Source
pub struct Polynomial<'a, B, T: Value = f64>
where B: Basis<T> + PolynomialDisplay<T>,
{ /* private fields */ }
Expand description

Represents a polynomial function in a given basis.

Unlike crate::CurveFit, this struct is not tied to any dataset or matrix, making it a canonical function that can be evaluated for any x-value without range restrictions.

§Type Parameters

Implementations§

Source§

impl<'a, T: Value> Polynomial<'a, MonomialBasis<T>, T>

Source

pub const fn borrowed(coefficients: &'a [T]) -> Self

Creates a new borrowed monomial polynomial from a slice of coefficients.

§Parameters
  • coefficients: Slice of coefficients, starting from the constant term.
§Example
let poly = MonomialPolynomial::borrowed(&[1.0, 2.0, 3.0]); // 1 + 2x + 3x^2
Source

pub const fn owned(coefficients: Vec<T>) -> Self

Creates a new owned monomial polynomial from a vector of coefficients.

§Parameters
  • coefficients: Vec of coefficients, starting from the constant term.
§Example
let poly = MonomialPolynomial::owned(vec![1.0, 2.0, 3.0]); // 1 + 2x + 3x^2
Source§

impl<T: Value> Polynomial<'_, FourierBasis<T>, T>

Source

pub fn new(x_range: (T, T), constant: T, terms: &[(T, T)]) -> Self

Create a new Fourier polynomial with the given constant and Fourier coefficients over the specified x-range.

§Parameters
  • x_range: The range of x-values over which the Fourier basis is defined
  • constant: The constant term of the polynomial
  • terms: A slice of (a_n, b_n) pairs representing the sine and cosine coefficients
§Returns

A polynomial defined in the Fourier basis.

For example to create a Fourier polynomial:

f(x) = 3 + 2 sin(2πx) - 0.5 cos(2πx)
use polyfit::FourierPolynomial;
let poly = FourierPolynomial::new((-1.0, 1.0), 3.0, &[(2.0, -0.5)]);
Source§

impl<'a, B, T: Value> Polynomial<'a, B, T>
where B: Basis<T> + PolynomialDisplay<T>,

Source

pub const unsafe fn from_raw( basis: B, coefficients: Cow<'a, [T]>, degree: usize, ) -> Self

Creates a Polynomial from a given basis, coefficients, and degree.

§Safety

This constructor is unsafe because it allows the creation of a polynomial without enforcing the usual invariants (e.g., degree must match the number of coefficients expected by the basis).

The length of coefficients must be equal to Basis::k(degree)

§Parameters
  • basis: The polynomial basis
  • coefficients: The coefficients for the polynomial, possibly borrowed or owned
  • degree: The degree of the polynomial
§Returns

A new Polynomial instance with the given basis and coefficients.

Source

pub fn from_basis( basis: B, coefficients: impl Into<Cow<'a, [T]>>, ) -> Result<Self>

Creates a new polynomial from a basis and coefficients, inferring the degree.

§Parameters
  • basis: The polynomial basis
  • coefficients: The coefficients for the polynomial, possibly borrowed or owned
§Returns

A new Polynomial instance with the given basis and coefficients, or an error if the number of coefficients is invalid for the basis.

§Errors

Returns an error if the number of coefficients does not correspond to a valid degree for the given basis.

Source

pub fn into_inner(self) -> (B, Cow<'a, [T]>, usize)

Decomposes the polynomial into its basis, coefficients, and degree.

Source

pub fn into_owned(self) -> Polynomial<'static, B, T>

Converts the polynomial into an owned version.

This consumes the current Polynomial and returns a new one with 'static lifetime, owning both the basis and the coefficients.

Useful when you need a fully independent polynomial that does not borrow from any external data.

Source

pub fn coefficients(&self) -> &[T]

Returns a reference to the polynomial’s coefficients.

The index of each coefficient the jth basis function.

For example in a monomial expression y(x) = 2x^2 - 3x + 1; coefficients = [1.0, -3.0, 2.0]

Technical Details

Formally, for each coefficient j, and the jth basis function B_j(x), the relationship is:

y(x) = Σ (c_j * B_j(x))
Source

pub fn coefficients_mut(&mut self) -> &mut [T]

Returns a mutable reference to the polynomial’s coefficients.

The index of each coefficient the jth basis function.

For example in a monomial expression y(x) = 2x^2 - 3x + 1; coefficients = [1.0, -3.0, 2.0]

Technical Details

Formally, for each coefficient j, and the jth basis function B_j(x), the relationship is:

y(x) = Σ (c_j * B_j(x))
Source

pub fn degree(&self) -> usize

Returns the degree of the polynomial.

The number of actual components, or basis functions, in the expression of a degree is defined by the basis.

That number is called k. For most basis choices, k = degree + 1.

Source

pub fn abs(&mut self)

Replaces the coefficients of the polynomial in place with absolute values.

Source

pub fn scale(&mut self, factor: T)

Scales all coefficients of the polynomial by a given factor in place.

Source

pub fn y(&self, x: T) -> T

Evaluates the polynomial at a given x-value.

Technical Details

Given Basis::k coefficients and basis functions, and for each pair of coefficients c_j and basis function B_j(x), this function returns:

y(x) = Σ (c_j * B_j(x))
§Parameters
  • x: The point at which to evaluate the polynomial.
§Returns

The computed y-value using the polynomial basis and coefficients.

§Example
let poly = MonomialPolynomial::borrowed(&[1.0, 2.0, 3.0]); // Represents 1 + 2x + 3x^2
let y = poly.y(2.0); // evaluates 1 + 2*2 + 3*2^2 = 17.0
Source

pub fn solve(&self, x: impl IntoIterator<Item = T>) -> Vec<(T, T)>

Evaluates the polynomial at multiple x-values.

Technical Details

Given Basis::k coefficients and basis functions, and for each pair of coefficients c_j and basis function B_j(x), this function returns:

y(x) = Σ (c_j * B_j(x))
§Parameters
  • x: An iterator of x-values at which to evaluate the polynomial.
§Returns

A Vec of (x, y) pairs corresponding to each input value.

§Example
let poly = MonomialPolynomial::borrowed(&[1.0, 2.0, 3.0]); // 1 + 2x + 3x^2
let points = poly.solve(vec![0.0, 1.0, 2.0]);
// points = [(0.0, 1.0), (1.0, 6.0), (2.0, 17.0)]
Source

pub fn solve_range(&self, range: RangeInclusive<T>, step: T) -> Vec<(T, T)>

Evaluates the polynomial over a range of x-values with a fixed step.

Technical Details

Given Basis::k coefficients and basis functions, and for each pair of coefficients c_j and basis function B_j(x), this function returns:

y(x) = Σ (c_j * B_j(x))
§Parameters
  • range: The start and end of the x-values to evaluate.
  • step: The increment between successive x-values.
§Returns

A Vec of (x, y) pairs for each sampled point.

§Example
let poly = MonomialPolynomial::borrowed(&[1.0, 2.0, 3.0]); // 1 + 2x + 3x^2
let points = poly.solve_range(0.0..=2.0, 1.0);
// points = [(0.0, 1.0), (1.0, 6.0), (2.0, 17.0)]
Source

pub fn r_squared(&self, data: &[(T, T)]) -> T

Calculates the R-squared value for the model compared to provided data.

R-squared is a statistical measure of how well the polynomial explains the variance in the data. Values closer to 1 indicate a better fit.

§Parameters
  • data: A slice of (x, y) pairs to compare against the polynomial fit.

See statistics::r_squared for more details.

§Returns

The R-squared value as type T.

Source

pub fn remove_leading_zeros(&mut self)

Removes leading zero coefficients from the polynomial in place. For example, a polynomial y(x) = 0x^2 + x + 3 would become y(x) = x + 3

Source

pub fn leading_coefficient(&self) -> T

Returns the most-significant (leading) non-zero coefficient of the polynomial.

If all coefficients are zero, returns zero.

Source

pub fn derivative(&self) -> Result<Polynomial<'static, B::B2, T>>
where B: DifferentialBasis<T>,

Computes the derivative of this polynomial.

§Type Parameters
  • B2: The basis type for the derivative (determined by the implementing DifferentialBasis trait).
§Returns
  • Ok(Polynomial<'static, B2, T>): The derivative polynomial.
  • Err: If computing the derivative fails.
§Requirements
§Errors

If the basis cannot compute the derivative coefficients, an error is returned.

§Example
use polyfit::function;
function!(test(x) = 20.0 + 3.0 x^1 + 2.0 x^2 + 4.0 x^3);
let deriv = test.derivative().unwrap();
println!("Derivative: {:?}", deriv.coefficients());
Source

pub fn critical_points( &self, x_range: RangeInclusive<T>, ) -> Result<Vec<CriticalPoint<T>>>

Finds the critical points (where the derivative is zero) of a polynomial in this basis.

This corresponds to the polynomial’s local minima and maxima (The x values where curvature changes).

Technical Details

The critical points are found by solving the equation f'(x) = 0, where f'(x) is the derivative of the polynomial.

This is done with by finding the eigenvalues of the companion matrix of the derivative polynomial.

§Returns

A vector of x values where the critical points occur.

§Requirements
§Errors

Returns an error if the critical points cannot be found.

§Example
let poly = MonomialPolynomial::borrowed(&[1.0, 2.0, 3.0]); // 1 + 2x + 3x^2
let critical_points = poly.critical_points(0.0..=100.0).unwrap();
Source

pub fn roots(&self) -> Result<Vec<Root<T>>>
where B: RootFindingBasis<T>,

Finds the roots (zeros) of the polynomial in this basis.

This corresponds to the x values where the polynomial evaluates to zero.

A root can be either real or complex:

  • Root::Real(x) indicates a real root at x. This is a point where the polynomial crosses or touches the x-axis.
  • Root::ComplexPair(z, z2) indicates a pair of complex conjugate roots. These do not correspond to x-axis crossings but are important in the polynomial’s overall behavior.
  • Root::Complex(z) indicates a single complex root (not part of a conjugate pair). Should be rare for polynomials with real coefficients.

Technical Details

The roots are found by solving the equation f(x) = 0, where f(x) is the polynomial.

This is done in a basis-specific manner, often involving finding the eigenvalues of the companion matrix of the polynomial.

§Returns

A vector of Root<T> representing the roots of the polynomial.

§Errors

Returns an error if the roots cannot be found.

Source

pub fn real_roots( &self, x_range: RangeInclusive<T>, max_newton_iterations: Option<usize>, ) -> Result<Vec<T>>
where B: DifferentialBasis<T>,

Uses a less precise iterative method to find only the real roots of the polynomial.

This is less precise than Self::roots and will not find complex roots, but is often faster and more stable for high-degree polynomials and is available for all bases.

§Parameters
  • x_range: The range of x-values to search for real roots.
  • max_newton_iterations: The maximum number of Newton-Raphson iterations to refine each root. This helps improve the accuracy of the found roots. If omitted, a sensible value will be calculated
§Returns

A vector of T representing the real roots of the polynomial within the specified range

§Errors

Returns an error if the derivative cannot be computed.

Source

pub fn integral( &self, constant: Option<T>, ) -> Result<Polynomial<'static, B::B2, T>>
where B: IntegralBasis<T>,

Computes the indefinite integral of this polynomial.

§Type Parameters
  • B2: The basis type for the integral (determined by the implementing DifferentialBasis trait).
§Parameters
  • constant: Constant of integration (value at x = 0).
§Requirements
§Returns
  • Ok(Polynomial<'static, B2, T>): The integral polynomial.
  • Err: If computing the integral fails.
§Errors

If the basis cannot compute the integral coefficients, an error is returned.

§Example
use polyfit::function;
function!(test(x) = 20.0 + 3.0 x^1 + 2.0 x^2 + 4.0 x^3);
let integral = test.integral(Some(1.0)).unwrap();
println!("Integral: {:?}", integral.coefficients());
Source

pub fn area_under_curve( &self, x_min: T, x_max: T, constant: Option<T>, ) -> Result<T>
where B: IntegralBasis<T>,

Computes the definite integral (area under the curve) of the fitted polynomial between x_min and x_max.

Technical Details

The area under the curve is computed using the definite integral of the polynomial between the specified bounds:

Area = ∫[x_min to x_max] f(x) dx = F(x_max) - F(x_min)
§Parameters
  • x_min: Lower bound of integration.
  • x_max: Upper bound of integration.
  • constant: Constant of integration (value at x = 0) for the indefinite integral.
§Requirements
§Returns
  • Ok(T): The computed area under the curve between x_min and x_max.
  • Err: If computing the integral fails (e.g., basis cannot compute integral coefficients).
§Errors

If the basis cannot compute the integral coefficients, an error is returned.

§Example
polyfit::function!(poly(x) = 4 x^3 + 2);
let area = poly.area_under_curve(0.0, 3.0, None).unwrap();
println!("Area under curve: {}", area);
Source

pub fn monotonicity_violations( &self, x_range: RangeInclusive<T>, ) -> Result<Vec<T>>
where B: DifferentialBasis<T>,

Returns the X-values where the function is not monotone (i.e., where the derivative changes sign).

§Errors

Returns an error if the derivative cannot be computed.

§Example
polyfit::function!(poly(x) = 4 x^3 + 2);
let area = poly.area_under_curve(0.0, 3.0, None).unwrap();
let violations = poly.monotonicity_violations(0.0..=3.0).unwrap();
Source

pub fn as_monomial(&self) -> Result<MonomialPolynomial<'static, T>>
where B: IntoMonomialBasis<T>,

Converts the polynomial into a monomial polynomial.

This produces a MonomialPolynomial representation of the curve, which uses the standard monomial basis 1, x, x^2, ….

§Returns

A monomial polynomial with owned coefficients.

§Errors

Returns an error if the current basis cannot be converted to monomial form. This requires that the basis implements IntoMonomialBasis.

§Example
let data = &[(0.0, 1.0), (1.0, 3.0), (2.0, 7.0)];
let fit = ChebyshevFit::new(data, 2).unwrap();
let mono_poly = fit.as_polynomial().as_monomial().unwrap();
let y = mono_poly.y(1.5);
Source

pub fn project<B2: Basis<T> + PolynomialDisplay<T>>( &self, x_range: RangeInclusive<T>, ) -> Result<Polynomial<'static, B2, T>>

Projects this polynomial onto another basis over a specified x-range.

This is useful for converting between different polynomial representations.

Technical Details

Gets 15 * k evenly spaced sample points over the specified range, where k is the number of coefficients in the current polynomial.

Fits a new polynomial in the target basis to these points using least-squares fitting.

§Type Parameters
  • B2: The target basis type to project onto.
§Parameters
  • x_range: The range of x-values over which to perform the projection.
§Returns
  • Ok(Polynomial<'static, B2, T>): The projected polynomial in the new basis.
§Errors

Returns an error if the projection fails, such as if the fitting process encounters issues.

Source

pub fn project_orthogonal<B2>( &self, x_range: RangeInclusive<T>, target_degree: usize, ) -> Result<Polynomial<'static, B2, T>>
where B2: Basis<T> + PolynomialDisplay<T> + OrthogonalBasis<T>,

Projects this polynomial onto an orthogonal basis over a specified x-range.

This is a -very- stable way to convert between polynomial bases, as it uses Gaussian quadrature

You can use it to leverage the strengths of different bases, for example:

  • If you have very very bad data
  • Fit a fourier curve of a moderate degree
    • This smooths out noise, but overexplains outliers and can ring at the edges
  • Then project that onto a Chebyshev basis of degree 2(degree of fourier - 1)
    • This makes sure you don’t create new information in the transfer
    • It drops 2 parameters to account for noise and the fourier ringing
  • The Chebyshev basis is well behaved and numerically stable
  • This will far outperform a direct fit to the noisy data
§Type Parameters
  • B2: The target orthogonal basis type to project onto.
  • T: The numeric type for the polynomial coefficients and evaluations.
§Parameters
  • x_range: The range of x-values over which to perform the projection.
  • target_degree: The degree of the target polynomial in the new basis.
§Returns
  • Ok(Polynomial<'static, B2, T>): The projected polynomial in the new orthogonal basis.
  • Err: If the projection fails, such as if the fitting process encounters issues.
§Errors

Returns an error if the projection fails, such as if the fitting process encounters issues.

Source

pub fn is_orthogonal(&self) -> bool
where B: OrthogonalBasis<T>,

Checks if the polynomial’s basis is orthogonal.

Can be used to determine if methods that require orthogonality can be applied. Returns true if the basis is orthogonal, false otherwise, like in the case of integrated Fourier series.

Source

pub fn coefficient_energies(&self) -> Result<Vec<T>>
where B: OrthogonalBasis<T>,

Computes the energy contribution of each coefficient in an orthogonal basis.

This is a measure of how much each basis function contributes to the resulting polynomial.

It can be useful for understanding the significance of each term

Technical Details

For an orthogonal basis, the energy contribution of each coefficient is calculated as:

E_j = c_j^2 * N_j

where:

  • E_j is the energy contribution of the jth coefficient.
  • c_j is the jth coefficient.
  • N_j is the normalization factor for the jth basis function, provided by the basis.
§Returns

A vector of energy contributions for each coefficient.

§Errors

Returns an error if the basis is not orthogonal. This can be checked with Polynomial::is_orthogonal. Can happen for integrated Fourier series

Source

pub fn smoothness(&self) -> Result<T>
where B: OrthogonalBasis<T>,

Computes a smoothness metric for the polynomial.

This metric quantifies how “smooth” the polynomial is, with lower values indicating smoother curves.

Technical Details

The smoothness is calculated as a weighted average of the coefficient energies, where higher-degree coefficients are penalized more heavily. The formula used is:

Smoothness = (Σ (k^2 * E_k)) / (Σ E_k)

where:

  • k is the degree of the basis function.
  • E_k is the energy contribution of the k-th coefficient.
§Returns

A smoothness value, where lower values indicate a smoother polynomial.

§Errors

Returns an error if the basis is not orthogonal. This can be checked with Polynomial::is_orthogonal.

Source

pub fn spectral_energy_filter(&mut self) -> Result<()>
where B: OrthogonalBasis<T>,

Applies a spectral energy filter to the polynomial.

This uses the properties of a orthogonal basis to de-noise the polynomial by removing higher-degree terms that contribute little to the overall energy. Terms are split into “signal” and “noise” based on their energy contributions, and the polynomial is truncated to only include the signal components.

Remaining terms are smoothly attenuated to prevent ringing artifacts from a hard cutoff.

Technical Details

The energy of each coefficient is calculated using the formula:

E_j = c_j^2 * N_j

where:

  • E_j is the energy contribution of the jth coefficient.
  • c_j is the jth coefficient.
  • N_j is the normalization factor for the jth basis function, provided by the basis.

Generalized Cross-Validation (GCV) is used to determine the optimal cutoff degree K that minimizes the prediction error using: GCV(K) = (suffix[0] - suffix[K]) / K^2, where suffix is the suffix sum of energies.

A Lanczos Sigma filter with p=1 is applied to smoothly attenuate coefficients up to the cutoff degree, reducing Gibbs ringing artifacts.

§Notes
  • This method modifies the polynomial in place.
§Errors

Returns an error if the basis is not orthogonal. This can be checked with Polynomial::is_orthogonal.

Source

pub fn equation(&self) -> String

Returns a human-readable string of the polynomial equation.

The output shows the polynomial in standard mathematical notation, for example:

y = 1.0x^3 + 2.0x^2 + 3.0x + 4.0
§Notes
  • Requires the basis to implement PolynomialDisplay for formatting.
  • This operation is infallible and guaranteed to succeed, hence no error return.
§Example
let poly = MonomialPolynomial::borrowed(&[1.0, 2.0, 3.0]); // 1 + 2x + 3x^2
println!("{}", poly.equation());

Trait Implementations§

Source§

impl<B, T> AsPlottingElement<T> for Polynomial<'_, B, T>
where B: Basis<T> + PolynomialDisplay<T>, T: Value,

Available on crate feature plotting only.
Source§

fn as_plotting_element( &self, xs: &[T], _: Confidence, _: Option<Tolerance<T>>, ) -> PlottingElement<T>

Converts this to a plotting element
Source§

impl<B, T: Value> AsRef<Polynomial<'_, B, T>> for CurveFit<'_, B, T>
where B: Basis<T> + PolynomialDisplay<T>,

Source§

fn as_ref(&self) -> &Polynomial<'static, B, T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, B, T: Value> AsRef<Polynomial<'a, B, T>> for Polynomial<'a, B, T>
where B: Basis<T> + PolynomialDisplay<T>,

Source§

fn as_ref(&self) -> &Polynomial<'a, B, T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, B, T: Clone + Value> Clone for Polynomial<'a, B, T>
where B: Basis<T> + PolynomialDisplay<T> + Clone,

Source§

fn clone(&self) -> Polynomial<'a, B, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, B, T: Debug + Value> Debug for Polynomial<'a, B, T>
where B: Basis<T> + PolynomialDisplay<T> + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<B, T: Value> Display for Polynomial<'_, B, T>
where B: Basis<T> + PolynomialDisplay<T>,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<B: Basis<T> + PolynomialDisplay<T>, T: Value> Div<T> for Polynomial<'_, B, T>

Source§

type Output = Polynomial<'static, B, T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<B: Basis<T> + PolynomialDisplay<T>, T: Value> DivAssign<T> for Polynomial<'_, B, T>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<B: Basis<T> + PolynomialDisplay<T>, T: Value> Mul<T> for Polynomial<'_, B, T>

Source§

type Output = Polynomial<'static, B, T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<B: Basis<T> + PolynomialDisplay<T>, T: Value> MulAssign<T> for Polynomial<'_, B, T>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<'a, B, T: PartialEq + Value> PartialEq for Polynomial<'a, B, T>
where B: Basis<T> + PolynomialDisplay<T> + PartialEq,

Source§

fn eq(&self, other: &Polynomial<'a, B, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, B, T: Value> StructuralPartialEq for Polynomial<'a, B, T>
where B: Basis<T> + PolynomialDisplay<T>,

Auto Trait Implementations§

§

impl<'a, B, T> Freeze for Polynomial<'a, B, T>
where B: Freeze,

§

impl<'a, B, T> RefUnwindSafe for Polynomial<'a, B, T>

§

impl<'a, B, T> Send for Polynomial<'a, B, T>

§

impl<'a, B, T> Sync for Polynomial<'a, B, T>

§

impl<'a, B, T> Unpin for Polynomial<'a, B, T>
where B: Unpin, T: Unpin,

§

impl<'a, B, T> UnwindSafe for Polynomial<'a, B, T>

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<E, T> WithTypeFrom<T> for E
where E: AsPlottingElement<T>, T: Value,

Source§

fn options_with_type_from(&self) -> PlotOptions<T>

Available on crate feature plotting only.
Get default plot options for this type
Source§

fn plot_with_type_from<P>( &self, root: &<P as PlotBackend>::Root, options: PlotOptions<T>, ) -> Result<Plot<P, T>, <P as PlotBackend>::Error>
where P: PlotBackend,

Available on crate feature plotting only.
Create a new plot with this as the primary function Read more
Source§

fn add_to_plot_with_type_from<P>( &self, plot: &mut Plot<P, T>, ) -> Result<(), <P as PlotBackend>::Error>
where P: PlotBackend,

Available on crate feature plotting only.
Adds this element to the given plot Read more
Source§

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

Source§

impl<T, Right> ClosedDiv<Right> for T
where T: Div<Right, Output = T> + DivAssign<Right>,

Source§

impl<T, Right> ClosedDivAssign<Right> for T
where T: ClosedDiv<Right> + DivAssign<Right>,

Source§

impl<T, Right> ClosedMul<Right> for T
where T: Mul<Right, Output = T> + MulAssign<Right>,

Source§

impl<T, Right> ClosedMulAssign<Right> for T
where T: ClosedMul<Right> + MulAssign<Right>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,