Make the error Send/Sync for anyhow
This commit is contained in:
parent
dd22d7a164
commit
1816118c7a
24
src/lib.rs
24
src/lib.rs
@ -36,7 +36,7 @@ pub enum Error {
|
|||||||
Slang(sys::SlangResult),
|
Slang(sys::SlangResult),
|
||||||
|
|
||||||
#[error("blob")]
|
#[error("blob")]
|
||||||
Blob(Blob),
|
Blob,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@ -45,13 +45,11 @@ pub(crate) fn succeeded(result: sys::SlangResult) -> bool {
|
|||||||
result.0 >= 0
|
result.0 >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn result_from_blob(code: sys::SlangResult, blob: *mut sys::slang_IBlob) -> Result<()> {
|
fn result_from_blob(code: sys::SlangResult, _blob: *mut sys::slang_IBlob) -> Result<()> {
|
||||||
if succeeded(code) {
|
if succeeded(code) {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(Error::Blob(Blob(IUnknown(
|
Err(Error::Blob)
|
||||||
std::ptr::NonNull::new(blob as *mut _).unwrap(),
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,10 +230,10 @@ impl Session {
|
|||||||
let module = vcall!(self, loadModule(name.as_ptr(), &mut diagnostics));
|
let module = vcall!(self, loadModule(name.as_ptr(), &mut diagnostics));
|
||||||
|
|
||||||
if module.is_null() {
|
if module.is_null() {
|
||||||
let blob = Blob(IUnknown(
|
let _blob = Blob(IUnknown(
|
||||||
std::ptr::NonNull::new(diagnostics as *mut _).unwrap(),
|
std::ptr::NonNull::new(diagnostics as *mut _).unwrap(),
|
||||||
));
|
));
|
||||||
Err(Error::Blob(blob))
|
Err(Error::Blob)
|
||||||
} else {
|
} else {
|
||||||
let module = Module(IUnknown(std::ptr::NonNull::new(module as *mut _).unwrap()));
|
let module = Module(IUnknown(std::ptr::NonNull::new(module as *mut _).unwrap()));
|
||||||
unsafe { (module.as_unknown().vtable().ISlangUnknown_addRef)(module.as_raw()) };
|
unsafe { (module.as_unknown().vtable().ISlangUnknown_addRef)(module.as_raw()) };
|
||||||
@ -319,9 +317,7 @@ impl ComponentType {
|
|||||||
let ptr = vcall!(self, getLayout(target, &mut diagnostics));
|
let ptr = vcall!(self, getLayout(target, &mut diagnostics));
|
||||||
|
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
Err(Error::Blob(Blob(IUnknown(
|
Err(Error::Blob)
|
||||||
std::ptr::NonNull::new(diagnostics as *mut _).unwrap(),
|
|
||||||
))))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(unsafe { &*(ptr as *const _) })
|
Ok(unsafe { &*(ptr as *const _) })
|
||||||
}
|
}
|
||||||
@ -714,6 +710,14 @@ impl OptionsBuilder {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compiles() {}
|
fn compiles() {}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_send_error() {
|
||||||
|
let lambda = |e: &(dyn std::error::Error + Send + Sync)| {};
|
||||||
|
lambda(&Error::Blob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ impl Shader {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_layout(&self, ty: &Type, rules: sys::SlangLayoutRules) -> Option<&TypeLayout> {
|
pub fn type_layout(&self, ty: &Type, rules: sys::SlangLayoutRules) -> Option<&TypeLayout> {
|
||||||
rcall!(
|
rcall!(
|
||||||
spReflection_GetTypeLayout(self, ty as *const _ as *mut _, rules)
|
spReflection_GetTypeLayout(self, ty as *const _ as *mut _, rules)
|
||||||
as Option<&TypeLayout>
|
as Option<&TypeLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user