Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
chore: upgrade safer_ffi to 0.1.0-rc1, with initial Doxygen-style \@C…
Browse files Browse the repository at this point in the history
…lass annotation output and renaming. (#282)
  • Loading branch information
jsantell authored Mar 22, 2023
1 parent 4cd2e3a commit b18bc2d
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 277 deletions.
147 changes: 101 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/noosphere/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ features = [
]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
safer-ffi = { version = "~0.0.10", features = ["proc_macros", "out-refs"] }
safer-ffi = { version = "0.1.0-rc1", features = ["proc_macros"] }
tokio = { version = "^1", features = ["full"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
Expand Down
9 changes: 6 additions & 3 deletions rust/noosphere/src/ffi/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::error::NoosphereError;

impl From<NoosphereError> for repr_c::Box<NsError> {
fn from(error: NoosphereError) -> Self {
repr_c::Box::new(NsError { inner: error })
Box::new(NsError { inner: error }).into()
}
}

Expand Down Expand Up @@ -45,8 +45,11 @@ impl TryOrInitialize<repr_c::Box<NsError>> for Option<Out<'_, repr_c::Box<NsErro
}
}

#[derive_ReprC]
#[ReprC::opaque]
#[derive_ReprC(rename = "ns_error")]
#[repr(opaque)]
/// @class ns_error_t
///
/// An error class.
pub struct NsError {
inner: NoosphereError,
}
Expand Down
22 changes: 15 additions & 7 deletions rust/noosphere/src/ffi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ use noosphere_sphere::{
SphereContext, SphereCursor, SphereFile, SphereWalker,
};

#[derive_ReprC]
#[ReprC::opaque]
#[derive_ReprC(rename = "ns_sphere")]
#[repr(opaque)]
/// @class ns_sphere_t
///
/// A sphere class.
pub struct NsSphere {
inner: SphereCursor<
Arc<Mutex<SphereContext<PlatformKeyMaterial, PlatformStorage>>>,
Expand Down Expand Up @@ -55,8 +58,11 @@ impl NsSphere {
}
}

#[derive_ReprC]
#[ReprC::opaque]
#[derive_ReprC(rename = "ns_sphere_file")]
#[repr(opaque)]
/// @class ns_sphere_file_t
///
/// TBD
pub struct NsSphereFile {
inner: SphereFile<Pin<Box<dyn AsyncRead>>>,
}
Expand Down Expand Up @@ -91,7 +97,7 @@ pub fn ns_sphere_fs_open(

let cursor = SphereCursor::latest(sphere_context);

Ok(repr_c::Box::new(NsSphere { inner: cursor })) as Result<_, anyhow::Error>
Ok(Box::new(NsSphere { inner: cursor }).into()) as Result<_, anyhow::Error>
})?;

Ok(fs)
Expand Down Expand Up @@ -148,9 +154,10 @@ pub fn ns_sphere_fs_read(
let file = cursor.read(&slug).await?;

Ok(file.map(|sphere_file| {
repr_c::Box::new(NsSphereFile {
Box::new(NsSphereFile {
inner: sphere_file.boxed(),
})
.into()
}))
})
.map_err(|error| error.into())
Expand Down Expand Up @@ -393,7 +400,8 @@ pub fn ns_sphere_file_header_value_first(
.memo
.get_first_header(name.to_str())
.into_iter()
.filter_map(|value| value.try_into().ok()).next()
.filter_map(|value| value.try_into().ok())
.next()
}

#[ffi_export]
Expand Down
Loading

0 comments on commit b18bc2d

Please sign in to comment.