Struct Percent
pub struct Percent<P>where
P: Polarity,{ /* private fields */ }Expand description
A percentage. The polarity fixes the range: Percent<Unipolar> takes 0 to
100, Percent<Bipolar> takes -100 to 100.
A unipolar value widens to a bipolar one with From; the reverse is a
TryFrom.
use sound_to_patch::units::{Bipolar, Percent, Unipolar};
let drive = Percent::<Unipolar>::new(25.0)?;
let amount = Percent::<Bipolar>::new(-100.0)?;
assert!(Percent::<Unipolar>::new(-1.0).is_err());
assert!(Percent::<Bipolar>::new(-101.0).is_err());Implementations§
Trait Implementations§
impl<P> Copy for Percent<P>where
P: Polarity,
§impl<'de, P> Deserialize<'de> for Percent<P>where
P: Polarity,
impl<'de, P> Deserialize<'de> for Percent<P>where
P: Polarity,
§fn deserialize<D>(
deserializer: D,
) -> Result<Percent<P>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Percent<P>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl<P> FromStr for Percent<P>where
P: Polarity,
impl<P> FromStr for Percent<P>where
P: Polarity,
§type Err = ParseUnitError
type Err = ParseUnitError
The associated error which can be returned from parsing.
§impl<P> PartialOrd for Percent<P>where
P: Polarity,
impl<P> PartialOrd for Percent<P>where
P: Polarity,
§impl<P> Serialize for Percent<P>where
P: Polarity,
impl<P> Serialize for Percent<P>where
P: Polarity,
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<P: Polarity> Spread for Percent<P>
Auto Trait Implementations§
impl<P> Freeze for Percent<P>
impl<P> RefUnwindSafe for Percent<P>where
P: RefUnwindSafe,
impl<P> Send for Percent<P>where
P: Send,
impl<P> Sync for Percent<P>where
P: Sync,
impl<P> Unpin for Percent<P>where
P: Unpin,
impl<P> UnsafeUnpin for Percent<P>
impl<P> UnwindSafe for Percent<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> ClampCast for Twhere
T: PartialOrd + Copy + 'static,
impl<T> ClampCast for Twhere
T: PartialOrd + Copy + 'static,
fn clamp_cast<O>(self) -> O
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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