Skip to content

Commit

Permalink
fix typeid bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MXWXZ committed Nov 5, 2024
1 parent 834f93f commit c1ee902
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 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 plugin/agent
Submodule agent updated 1 files
+6 −6 Cargo.lock
2 changes: 1 addition & 1 deletion plugin/monitor
Submodule monitor updated 2 files
+6 −6 Cargo.lock
+2 −2 src/lib.rs
2 changes: 1 addition & 1 deletion plugin/task
Submodule task updated 2 files
+6 −6 Cargo.lock
+4 −1 src/lib.rs
2 changes: 1 addition & 1 deletion skynet_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skynet_api"
version = "0.2.9"
version = "0.2.10"
edition = "2021"
authors = ["MXWXZ <[email protected]>"]
description = "API for Skynet plugin."
Expand Down
10 changes: 7 additions & 3 deletions skynet_api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ impl APIManager {
/// # Panics
///
/// Panics if `ver` is invalid.
pub fn get<T: Any>(&self, id: &HyUuid, ver: &str) -> Option<Arc<T>> {
pub fn get<T: Any>(&self, id: &HyUuid, ver: &str) -> Option<Arc<Box<T>>> {
let ver = VersionReq::parse(ver).unwrap();
self.api.get(id).and_then(|x| {
if ver.matches(&x.version) {
x.item.downcast_ref::<Arc<T>>().cloned()
let item = unsafe {
let raw = Arc::into_raw(x.item.clone()) as *const Box<T>;
Arc::from_raw(raw)
};
Some(item)
} else {
None
}
Expand All @@ -52,7 +56,7 @@ impl APIManager {
*id,
APIItem {
version: Version::parse(ver).unwrap(),
item: item.into(),
item: Arc::new(item),
},
);
}
Expand Down

0 comments on commit c1ee902

Please sign in to comment.