Skip to main content

CsdBuilder

Struct CsdBuilder 

Source
pub struct CsdBuilder { /* private fields */ }
Expand description

Builder for CSD conversion operations with configurable options

§Examples

use csd::{CsdBuilder, CsdError, CsdResult};

let csd = CsdBuilder::new(28.5)
    .places(4)
    .max_non_zeros(3)
    .build()?;
assert_eq!(csd, "+00-00.+");

Implementations§

Source§

impl CsdBuilder

Source

pub fn new(value: f64) -> Self

Create a new CsdBuilder with the given value.

§Arguments
  • value - The decimal value to convert to CSD
Source

pub fn places(self, places: i32) -> Self

Set the number of decimal places for the CSD output.

§Arguments
  • places - Number of decimal places (must be non-negative)
Source

pub fn max_non_zeros(self, max_non_zeros: u32) -> Self

Set the maximum number of non-zero digits allowed.

§Arguments
  • max_non_zeros - Maximum number of non-zero digits in the output
Source

pub fn rounding_strategy(self, strategy: RoundingStrategy) -> Self

Set the rounding strategy for conversion.

§Arguments
  • strategy - The rounding strategy to use
Source

pub fn build(self) -> CsdResult<String>

Build the CSD string from the configured builder.

§Errors

Returns an error if max_non_zeros is 0 but the value is non-zero.

Auto Trait Implementations§

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> 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, 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.