pub trait IntoDart {
// Required method
fn into_dart(self) -> DartCObject;
}
Expand description
A trait to convert between Rust types and Dart Types that could then be sent to the isolate
see: crate::Isolate::post
Required Methods§
Sourcefn into_dart(self) -> DartCObject
fn into_dart(self) -> DartCObject
Consumes Self
and Performs the conversion.
Implementations on Foreign Types§
Source§impl IntoDart for Vec<NaiveDateTime>
impl IntoDart for Vec<NaiveDateTime>
fn into_dart(self) -> DartCObject
Source§impl IntoDart for Vec<Uuid>
impl IntoDart for Vec<Uuid>
Source§fn into_dart(self) -> DartCObject
fn into_dart(self) -> DartCObject
⚠️ concatenated in a single Vec<u8>
for performance optimization
on the other side of FFI, value should be reconstructed like:
-
hydrate into Dart List<UuidValue>
return List<UuidValue>.generate( raw.lengthInBytes / 16, (int i) => UuidValue.fromByteList(Uint8List.view(raw.buffer, i * 16, 16)), growable: false);
-
hydrate into Rust Vec<Uuid>
ⓘraw .as_slice() .chunks(16) .map(|x: &[u8]| uuid::Uuid::from_bytes(*<&[u8] as std::convert::TryInto<&[u8;16]>>::try_into(x).expect("invalid uuid slice"))) .collect();
note that buffer could end up being incomplete under the same conditions as of std::io::Write::write.
Source§impl IntoDart for DateTime<Local>
impl IntoDart for DateTime<Local>
Source§fn into_dart(self) -> DartCObject
fn into_dart(self) -> DartCObject
on the other side of FFI, value should be reconstructed like:
-
hydrate into Dart DateTime
DateTime.fromMicrosecondsSinceEpoch(raw, isUtc: false);
-
hydrate into Rust DateTime::<Local>
ⓘlet s = (raw / 1_000_000) as i64; let ns = (raw.rem_euclid(1_000_000) * 1_000) as u32; chrono::DateTime::<chrono::Local>::from( chrono::DateTime::<chrono::Utc>::from_utc( chrono::NaiveDateTime::from_timestamp(s, ns), chrono::Utc));
note that it could overflow under the same conditions as of chrono::NaiveDateTime::from_timestamp
Source§impl IntoDart for DateTime<Utc>
impl IntoDart for DateTime<Utc>
Source§fn into_dart(self) -> DartCObject
fn into_dart(self) -> DartCObject
on the other side of FFI, value should be reconstructed like:
-
hydrate into Dart DateTime
DateTime.fromMicrosecondsSinceEpoch(raw, isUtc: true);
-
hydrate into Rust DateTime::<Utc>
ⓘlet s = (raw / 1_000_000) as i64; let ns = (raw.rem_euclid(1_000_000) * 1_000) as u32; chrono::DateTime::<chrono::Utc>::from_utc( chrono::NaiveDateTime::from_timestamp(s, ns), chrono::Utc);
note that it could overflow under the same conditions as of chrono::NaiveDateTime::from_timestamp
Source§impl IntoDart for NaiveDate
impl IntoDart for NaiveDate
Source§fn into_dart(self) -> DartCObject
fn into_dart(self) -> DartCObject
on the other side of FFI, value should be reconstructed like:
-
hydrate into Dart DateTime
DateTime.fromMicrosecondsSinceEpoch(raw, isUtc: true);
-
hydrate into Rust NaiveDateTime
ⓘlet s = (raw / 1_000_000) as i64; let ns = (raw.rem_euclid(1_000_000) * 1_000) as u32; chrono::NaiveDateTime::from_timestamp(s, ns)
note that it could overflow under the same conditions as of chrono::NaiveDateTime::from_timestamp
Source§impl IntoDart for NaiveDateTime
impl IntoDart for NaiveDateTime
Source§fn into_dart(self) -> DartCObject
fn into_dart(self) -> DartCObject
on the other side of FFI, value should be reconstructed like:
-
hydrate into Dart DateTime
DateTime.fromMicrosecondsSinceEpoch(raw, isUtc: true);
-
hydrate into Rust NaiveDateTime
ⓘlet s = (raw / 1_000_000) as i64; let ns = (raw.rem_euclid(1_000_000) * 1_000) as u32; chrono::NaiveDateTime::from_timestamp(s, ns)
note that it could overflow under the same conditions as of chrono::NaiveDateTime::from_timestamp
Source§impl IntoDart for Uuid
impl IntoDart for Uuid
Source§fn into_dart(self) -> DartCObject
fn into_dart(self) -> DartCObject
delegate to Vec<u8>
implementation
on the other side of FFI, value should be reconstructed like: