Struct sqlx_mysql::types::MySqlTime
source · pub struct MySqlTime { /* private fields */ }
Expand description
Container for a MySQL TIME
value, which may be an interval or a time-of-day.
Allowed range is -838:59:59.0
to 838:59:59.0
.
If this value is used for a time-of-day, the range should be 00:00:00.0
to 23:59:59.999999
.
You can use Self::is_valid_time_of_day()
to check this easily.
Implementations§
source§impl MySqlTime
impl MySqlTime
sourcepub fn new(
sign: MySqlTimeSign,
hours: u32,
minutes: u8,
seconds: u8,
microseconds: u32,
) -> Result<Self, MySqlTimeError>
pub fn new( sign: MySqlTimeSign, hours: u32, minutes: u8, seconds: u8, microseconds: u32, ) -> Result<Self, MySqlTimeError>
Construct a MySqlTime
that is valid for use as a TIME
value.
§Errors
MySqlTimeError::NegativeZero
if all fields are 0 butsign
isMySqlTimeSign::Negative
.MySqlTimeError::FieldRange
if any field is out of range:hours > 838
minutes > 59
seconds > 59
microseconds > 999_999
MySqlTimeError::SubsecondExcess
if the magnitude is less than one second over the maximum.- Durations 839 hours or greater are covered by
FieldRange
.
- Durations 839 hours or greater are covered by
sourcepub fn with_sign(self, sign: MySqlTimeSign) -> Self
pub fn with_sign(self, sign: MySqlTimeSign) -> Self
Update the sign
of this value.
sourcepub fn sign(&self) -> MySqlTimeSign
pub fn sign(&self) -> MySqlTimeSign
Return the sign (positive or negative) for this TIME value.
sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns true
if self
is zero (equal to Self::ZERO
).
sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true
if self
is positive or zero, false
if negative.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true
if self
is negative, false
if positive or zero.
sourcepub fn is_valid_time_of_day(&self) -> bool
pub fn is_valid_time_of_day(&self) -> bool
Returns true
if this interval is a valid time-of-day.
If true
, the sign is positive and hours
is not greater than 23.
sourcepub fn hours(&self) -> u32
pub fn hours(&self) -> u32
Get the total number of hours in this interval, from 0 to 838.
If this value represents a time-of-day, the range is 0 to 23.
sourcepub fn microseconds(&self) -> u32
pub fn microseconds(&self) -> u32
Get the number of seconds in this interval, from 0 to 999,999.
sourcepub fn to_duration(&self) -> Option<Duration>
pub fn to_duration(&self) -> Option<Duration>
Convert this TIME value to a std::time::Duration
.
Returns None
if this value is negative (cannot be represented).
Trait Implementations§
source§impl<'q> Encode<'q, MySql> for MySqlTime
impl<'q> Encode<'q, MySql> for MySqlTime
source§fn encode_by_ref(
&self,
buf: &mut <MySql as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, BoxDynError>
fn encode_by_ref( &self, buf: &mut <MySql as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, BoxDynError>
fn size_hint(&self) -> usize
source§fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
source§impl Ord for MySqlTime
impl Ord for MySqlTime
source§impl PartialOrd for MySqlTime
impl PartialOrd for MySqlTime
source§impl TryFrom<Duration> for MySqlTime
impl TryFrom<Duration> for MySqlTime
Convert MySqlTime
from std::time::Duration
.
§Note: Precision Truncation
Duration
supports nanosecond precision, but MySQL TIME
values only support microsecond
precision.
For simplicity, higher precision values are truncated when converting.
If you prefer another rounding mode instead, you should apply that to the Duration
first.
See also: MySQL Manual, section 13.2.6: Fractional Seconds in Time Values
§Errors:
Returns MySqlTimeError::FieldRange
if the given duration is longer than 838:59:59.999999
.
impl Copy for MySqlTime
impl Eq for MySqlTime
impl StructuralPartialEq for MySqlTime
Auto Trait Implementations§
impl Freeze for MySqlTime
impl RefUnwindSafe for MySqlTime
impl Send for MySqlTime
impl Sync for MySqlTime
impl Unpin for MySqlTime
impl UnwindSafe for MySqlTime
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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