pub trait SampleFrom: Numeric {
type ImplFor;
// Required methods
fn to<S>(s: S) -> Self
where S: SampleType;
fn as_<S>(s: S) -> Self
where S: SampleType;
fn sin<S>(s: S) -> Self
where S: SampleType;
fn cos<S>(s: S) -> Self
where S: SampleType;
}
Expand description
- The
SampleFrom
as a utility forSampleType
to handle function overloading
Required Associated Types§
Required Methods§
Sourcefn to<S>(s: S) -> Selfwhere
S: SampleType,
fn to<S>(s: S) -> Selfwhere
S: SampleType,
The to<S>
method, input any type of SampleType
value, then scale it to ImplFor
type.
Sourcefn as_<S>(s: S) -> Selfwhere
S: SampleType,
fn as_<S>(s: S) -> Selfwhere
S: SampleType,
The as_<S>
method, input any type of SampleType
value, then cast it to ImplFor
type.
Sourcefn sin<S>(s: S) -> Selfwhere
S: SampleType,
fn sin<S>(s: S) -> Selfwhere
S: SampleType,
Sine wave generator
- The input
x
doesn’t need to be related to PI. - e.g. The type is
i8
, the value is -128, then you will get sin(-PI). - e.g. The type is
u8
, the value is 0, then you will get sin(-PI) too.
Sourcefn cos<S>(s: S) -> Selfwhere
S: SampleType,
fn cos<S>(s: S) -> Selfwhere
S: SampleType,
Cosine wave generator
- The input
x
doesn’t need to be related to PI. - e.g. The type is
i8
, the value is -128, then you will get cos(-PI). - e.g. The type is
u8
, the value is 0, then you will get cos(-PI) too.
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.