Struct Curve

Source
pub struct Curve(/* private fields */);
Expand description

A representation of a piecewise-linear, weakly monotone decreasing demand curve

Demand curves define a bidder’s willingness to pay for different quantities of a good. In flow trading, these curves must be:

  • Piecewise-linear (defined by a sequence of points)
  • Weakly monotone decreasing (price non-increasing as rate increases)
  • Include the point rate=0 in their domain (must allow zero trade)

Implementations§

Source§

impl Curve

Source

pub fn new(points: Vec<Point>) -> Result<Self, ValidationError>

Creates a new demand curve from a sequence of points

Validates that the points:

  • Are not empty
  • Have valid (non-NaN, non-infinite) coordinates
  • Are ordered by ascending rate and descending price
  • Include rate=0 in their domain (first point rate ≤ 0, last point rate ≥ 0)

Returns a ValidationError if any of these conditions are not met.

Source

pub unsafe fn new_unchecked(points: Vec<Point>) -> Self

Creates a new Curve without validating the points

§Safety

This function should only be used when the caller can guarantee that the points satisfy all the requirements that new would check. Using invalid points can lead to incorrect behavior in downstream systems.

Source

pub fn into_iter(self) -> impl Iterator<Item = Point>

Converts the curve into an iterator over its points

Source

pub fn scale(&self, x: f64) -> Vec<(f64, f64)>

Scales the rate component of each point by the given factor

Returns a vector of (scaled_rate, price) tuples. This is useful when converting between rate-based and quantity-based representations.

Source§

impl Curve

Source

pub fn as_solver(&self, scale: f64) -> PiecewiseLinearCurve

Removes any collinearities and scales by the provided value

This optimizes the curve representation by:

  1. Removing intermediate points that lie on the same line segment
  2. Scaling rates by the provided factor to convert to quantities

The resulting curve is suitable for use with the solver library.

Trait Implementations§

Source§

impl Clone for Curve

Source§

fn clone(&self) -> Curve

Returns a copy 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 ComposeSchema for Curve

Source§

impl Debug for Curve

Source§

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

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

impl<'de> Deserialize<'de> for Curve

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Into<Vec<Point>> for Curve

Source§

fn into(self) -> Vec<Point>

Converts the Curve back into a vector of Points

Source§

impl PartialEq for Curve

Source§

fn eq(&self, other: &Curve) -> 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 Serialize for Curve

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToSchema for Curve

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this type. Read more
Source§

impl TryFrom<Vec<Point>> for Curve

Source§

fn try_from(value: Vec<Point>) -> Result<Self, Self::Error>

Attempts to create a Curve from a vector of points

Delegates to Curve::new for validation.

Source§

type Error = ValidationError

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

impl StructuralPartialEq for Curve

Auto Trait Implementations§

§

impl Freeze for Curve

§

impl RefUnwindSafe for Curve

§

impl Send for Curve

§

impl Sync for Curve

§

impl Unpin for Curve

§

impl UnwindSafe for Curve

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> PartialSchema for T
where T: ComposeSchema + ?Sized,

Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
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, 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,