taskchampion_lib/
atomic.rs

1//! Trait implementations for a few atomic types
2
3use crate::traits::*;
4use taskchampion::chrono::{DateTime, Utc};
5use taskchampion::utc_timestamp;
6
7impl PassByValue for usize {
8    type RustType = usize;
9
10    unsafe fn from_ctype(self) -> usize {
11        self
12    }
13
14    fn as_ctype(arg: usize) -> usize {
15        arg
16    }
17}
18
19/// Convert an Option<DateTime<Utc>> to a libc::time_t, or zero if not set.
20impl PassByValue for libc::time_t {
21    type RustType = Option<DateTime<Utc>>;
22
23    unsafe fn from_ctype(self) -> Option<DateTime<Utc>> {
24        if self != 0 {
25            return Some(utc_timestamp(self));
26        }
27        None
28    }
29
30    fn as_ctype(arg: Option<DateTime<Utc>>) -> libc::time_t {
31        arg.map(|ts| ts.timestamp() as libc::time_t)
32            .unwrap_or(0 as libc::time_t)
33    }
34}