-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] Start implementing FFI for manifest, picklist and selection
- Loading branch information
Showing
8 changed files
with
537 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::manifest::{Manifest, Record}; | ||
|
||
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(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.