pub trait ComplexScalarSetParts: ComplexScalarGetParts {
// Required methods
fn set_real_part(&mut self, real_part: Self::RealType);
fn set_imaginary_part(&mut self, imag_part: Self::RealType);
// Provided methods
fn with_real_part(self, real_part: Self::RealType) -> Self { ... }
fn with_imaginary_part(self, imag_part: Self::RealType) -> Self { ... }
}Expand description
Trait for setting the real and imaginary components of a complex scalar.
This trait provides methods to modify the components of a complex number, either by mutation or by creating a new value with modified components.
§Examples
use num_valid::{ComplexNative64StrictFinite, RealNative64StrictFinite};
use num_valid::functions::{ComplexScalarConstructors, ComplexScalarSetParts, ComplexScalarGetParts};
use try_create::TryNew;
let z = ComplexNative64StrictFinite::try_new_complex(3.0, 4.0).unwrap();
let new_real = RealNative64StrictFinite::try_new(10.0).unwrap();
// Create a new complex number with modified real part
let z_modified = z.with_real_part(new_real);
assert_eq!(*z_modified.raw_real_part(), 10.0);
assert_eq!(*z_modified.raw_imag_part(), 4.0);Required Methods§
Sourcefn set_real_part(&mut self, real_part: Self::RealType)
fn set_real_part(&mut self, real_part: Self::RealType)
Set the real part of the complex number.
Sourcefn set_imaginary_part(&mut self, imag_part: Self::RealType)
fn set_imaginary_part(&mut self, imag_part: Self::RealType)
Set the imaginary part of the complex number.
Provided Methods§
Sourcefn with_real_part(self, real_part: Self::RealType) -> Self
fn with_real_part(self, real_part: Self::RealType) -> Self
Returns a new complex number with the real part set to the given value and the imaginary part from self.
Sourcefn with_imaginary_part(self, imag_part: Self::RealType) -> Self
fn with_imaginary_part(self, imag_part: Self::RealType) -> Self
Returns a new complex number with the imaginary part set to the given value and the real part from self.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl ComplexScalarSetParts for Complex<f64>
Implement the ComplexScalarSetParts trait for the Complex<f64> type.
impl ComplexScalarSetParts for Complex<f64>
Implement the ComplexScalarSetParts trait for the Complex<f64> type.
Source§fn set_real_part(&mut self, real_part: f64)
fn set_real_part(&mut self, real_part: f64)
Set the value of the real part.
§Panics
In debug builds, this will panic if real_part is not finite.
This check is disabled in release builds for performance.
Source§fn set_imaginary_part(&mut self, imag_part: f64)
fn set_imaginary_part(&mut self, imag_part: f64)
Set the value of the imaginary part.
§Panics
In debug builds, this will panic if imag_part is not finite.
This check is disabled in release builds for performance.
Implementors§
impl<K: NumKernel> ComplexScalarSetParts for ComplexValidated<K>
Implement the ComplexScalarSetParts trait for the ComplexValidated type.