-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::manifest::{Manifest, Record}; | ||
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / Check
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / Lints (beta)
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / Lints (stable)
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / Run tests under wasm32-wasi
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / test (stable)
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / test (beta)
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / test (macos)
Check failure on line 1 in src/core/src/ffi/manifest.rs GitHub Actions / minimum_rust_version
|
||
|
||
use crate::ffi::utils::{ForeignObject, SourmashStr}; | ||
|
||
pub struct SourmashManifest; | ||
|
||
impl ForeignObject for SourmashManifest { | ||
type RustObject = Manifest; | ||
} | ||
|
||
pub struct ManifestRowIterator { | ||
iter: Box<dyn Iterator<Item = &'static Record>>, | ||
} | ||
|
||
pub struct SourmashManifestRowIter; | ||
|
||
impl ForeignObject for SourmashManifestRowIter { | ||
type RustObject = ManifestRowIterator; | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn manifest_rows_iter_next( | ||
ptr: *mut SourmashManifestRowIter, | ||
) -> *const SourmashManifestRow { | ||
let iterator = SourmashManifestRowIter::as_rust_mut(ptr); | ||
|
||
match iterator.iter.next() { | ||
Some(row) => SourmashManifestRow::from_rust(row.into()), | ||
None => std::ptr::null(), | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn manifest_rows( | ||
ptr: *const SourmashManifest, | ||
) -> *mut SourmashManifestRowIter { | ||
let manifest = SourmashManifest::as_rust(ptr); | ||
|
||
let iter = Box::new(manifest.iter()); | ||
SourmashManifestRowIter::from_rust(ManifestRowIterator { iter }) | ||
} | ||
|
||
#[repr(C)] | ||
pub struct SourmashManifestRow { | ||
pub ksize: u32, | ||
pub with_abundance: u8, | ||
pub md5: SourmashStr, | ||
pub internal_location: SourmashStr, | ||
pub name: SourmashStr, | ||
pub moltype: SourmashStr, | ||
} | ||
|
||
impl ForeignObject for SourmashManifestRow { | ||
type RustObject = SourmashManifestRow; | ||
} | ||
|
||
impl From<&Record> for SourmashManifestRow { | ||
fn from(record: &Record) -> SourmashManifestRow { | ||
Self { | ||
ksize: record.ksize(), | ||
with_abundance: record.with_abundance() as u8, | ||
md5: record.md5().into(), | ||
name: record.name().into(), | ||
moltype: record.moltype().to_string().into(), | ||
internal_location: record | ||
.internal_location() | ||
.to_str() | ||
.unwrap() | ||
.to_owned() | ||
.into(), | ||
} | ||
} | ||
} |