Struct TimeFrame
pub struct TimeFrame {
pub quantity: NonZero<u32>,
pub unit: TimeUnit,
}Expand description
Represents a timeframe with a quantity and a unit.
Timeframes specify the bar duration for chart data (e.g. 1 day, 5 minutes).
They can be created with convenience constructors, the general
new() method, or by parsing a string.
§Examples
use navi_types::{TimeFrame, TimeUnit};
// Convenience constructors
let daily = TimeFrame::days(1);
let five_min = TimeFrame::minutes(5);
let weekly = TimeFrame::weeks(1);
// General constructor
let monthly = TimeFrame::new(3, TimeUnit::Month);
// Parse from timeframe strings
let tf: TimeFrame = "D".parse().unwrap(); // 1 day
assert_eq!(tf, TimeFrame::days(1));
let tf: TimeFrame = "60".parse().unwrap(); // 60 minutes
assert_eq!(tf, TimeFrame::minutes(60));
let tf: TimeFrame = "4W".parse().unwrap(); // 4 weeks
assert_eq!(tf, TimeFrame::weeks(4));
// Display back to string
assert_eq!(TimeFrame::days(1).to_string(), "D");
assert_eq!(TimeFrame::minutes(5).to_string(), "5");
assert_eq!(TimeFrame::months(3).to_string(), "3M");Fields§
§quantity: NonZero<u32>Number of units in the timeframe.
unit: TimeUnitBase unit for the timeframe.
Implementations§
§impl TimeFrame
impl TimeFrame
pub fn seconds(quantity: u32) -> TimeFrame
pub fn seconds(quantity: u32) -> TimeFrame
Creates a TimeFrame representing the given number of seconds.
pub fn minutes(quantity: u32) -> TimeFrame
pub fn minutes(quantity: u32) -> TimeFrame
Creates a TimeFrame representing the given number of minutes.
pub fn months(quantity: u32) -> TimeFrame
pub fn months(quantity: u32) -> TimeFrame
Creates a TimeFrame representing the given number of months.
pub fn multiplier(&self) -> u32
pub fn multiplier(&self) -> u32
Returns the multiplier (quantity) of the timeframe.
For example, ‘60’ - 60, ‘D’ - 1, ‘5W’ - 5.
pub fn in_seconds(&self) -> Option<u64>
pub fn in_seconds(&self) -> Option<u64>
Returns the timeframe duration in seconds, if representable.
pub fn from_seconds(seconds: i64) -> TimeFrame
pub fn from_seconds(seconds: i64) -> TimeFrame
Chooses a coarse TimeFrame that best fits seconds.
Trait Implementations§
§impl<'de> Deserialize<'de> for TimeFrame
impl<'de> Deserialize<'de> for TimeFrame
§fn deserialize<D>(
deserializer: D,
) -> Result<TimeFrame, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<TimeFrame, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl Serialize for TimeFrame
impl Serialize for TimeFrame
§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 Copy for TimeFrame
impl Eq for TimeFrame
impl StructuralPartialEq for TimeFrame
Auto Trait Implementations§
impl Freeze for TimeFrame
impl RefUnwindSafe for TimeFrame
impl Send for TimeFrame
impl Sync for TimeFrame
impl Unpin for TimeFrame
impl UnsafeUnpin for TimeFrame
impl UnwindSafe for TimeFrame
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.