This is an automated email from the ASF dual-hosted git repository. chaokunyang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/fory-site.git
commit a41b0f270247dc2b0e07817ab6ea5320083a89a0 Author: chaokunyang <[email protected]> AuthorDate: Wed Jun 3 22:23:15 2026 +0000 ๐ synced local 'docs/guide/' with remote 'docs/guide/' --- docs/guide/rust/configuration.md | 2 +- docs/guide/rust/native-serialization.md | 2 +- docs/guide/rust/polymorphism.md | 19 +++++++------------ docs/guide/rust/schema-evolution.md | 4 +++- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/docs/guide/rust/configuration.md b/docs/guide/rust/configuration.md index 83fc6e538c..d140f0357c 100644 --- a/docs/guide/rust/configuration.md +++ b/docs/guide/rust/configuration.md @@ -80,7 +80,7 @@ let fory = Fory::builder().xlang(true).max_dyn_depth(10).build(); // Allow up to **Protected types:** -- `Box<dyn Any>`, `Rc<dyn Any>`, `Arc<dyn Any>` +- `Box<dyn Any>`, `Rc<dyn Any>`, `Arc<dyn Any + Send + Sync>` - `Box<dyn Trait>`, `Rc<dyn Trait>`, `Arc<dyn Trait>` (trait objects) - `RcWeak<T>`, `ArcWeak<T>` - Collection types (Vec, HashMap, HashSet) diff --git a/docs/guide/rust/native-serialization.md b/docs/guide/rust/native-serialization.md index cba76f7010..e2bf6e74f4 100644 --- a/docs/guide/rust/native-serialization.md +++ b/docs/guide/rust/native-serialization.md @@ -100,7 +100,7 @@ Native serialization owns the Rust-specific object surface: - `Box<T>`, `Rc<T>`, `Arc<T>`, `RcWeak<T>`, and `ArcWeak<T>`. - `RefCell<T>` and `Mutex<T>`. - Trait objects such as `Box<dyn Trait>`, `Rc<dyn Trait>`, and `Arc<dyn Trait>`. -- Runtime type dispatch with `Rc<dyn Any>` and `Arc<dyn Any>`. +- Runtime type dispatch with `Rc<dyn Any>` and `Arc<dyn Any + Send + Sync>`. - Date and time carriers, including optional `chrono` support. Use [Basic Serialization](basic-serialization.md), [References](references.md), and diff --git a/docs/guide/rust/polymorphism.md b/docs/guide/rust/polymorphism.md index 1f21d9eacd..fa87735edd 100644 --- a/docs/guide/rust/polymorphism.md +++ b/docs/guide/rust/polymorphism.md @@ -85,7 +85,8 @@ assert_eq!(decoded.star_animal.speak(), "Woof!"); ## Serializing dyn Any Trait Objects -Apache Foryโข supports serializing `Rc<dyn Any>` and `Arc<dyn Any>` for runtime type dispatch: +Apache Foryโข supports serializing `Rc<dyn Any>` and +`Arc<dyn Any + Send + Sync>` for runtime type dispatch: **Key points:** @@ -98,14 +99,11 @@ Apache Foryโข supports serializing `Rc<dyn Any>` and `Arc<dyn Any>` for runtime use std::rc::Rc; use std::any::Any; -let dog_rc: Rc<dyn Animal> = Rc::new(Dog { +let dog_any: Rc<dyn Any> = Rc::new(Dog { name: "Rex".to_string(), breed: "Golden".to_string() }); -// Convert to Rc<dyn Any> for serialization -let dog_any: Rc<dyn Any> = dog_rc.clone(); - // Serialize the Any wrapper let bytes = fory.serialize(&dog_any)?; let decoded: Rc<dyn Any> = fory.deserialize(&bytes)?; @@ -115,22 +113,19 @@ let unwrapped = decoded.downcast_ref::<Dog>().unwrap(); assert_eq!(unwrapped.name, "Rex"); ``` -For thread-safe scenarios, use `Arc<dyn Any>`: +For thread-safe scenarios, use `Arc<dyn Any + Send + Sync>`: ```rust use std::sync::Arc; use std::any::Any; -let dog_arc: Arc<dyn Animal> = Arc::new(Dog { +let dog_any: Arc<dyn Any + Send + Sync> = Arc::new(Dog { name: "Buddy".to_string(), breed: "Labrador".to_string() }); -// Convert to Arc<dyn Any> -let dog_any: Arc<dyn Any> = dog_arc.clone(); - let bytes = fory.serialize(&dog_any)?; -let decoded: Arc<dyn Any> = fory.deserialize(&bytes)?; +let decoded: Arc<dyn Any + Send + Sync> = fory.deserialize(&bytes)?; // Downcast to concrete type let unwrapped = decoded.downcast_ref::<Dog>().unwrap(); @@ -185,7 +180,7 @@ assert_eq!(decoded.animals_arc[0].speak(), "Woof!"); Due to Rust's orphan rule, `Rc<dyn Trait>` and `Arc<dyn Trait>` cannot implement `Serializer` directly. For standalone serialization (not inside struct fields), the `register_trait_type!` macro generates wrapper types. -**Note:** If you don't want to use wrapper types, you can serialize as `Rc<dyn Any>` or `Arc<dyn Any>` instead (see the dyn Any section above). +**Note:** If you don't want to use wrapper types, you can serialize as `Rc<dyn Any>` or `Arc<dyn Any + Send + Sync>` instead (see the dyn Any section above). The `register_trait_type!` macro generates `AnimalRc` and `AnimalArc` wrapper types: diff --git a/docs/guide/rust/schema-evolution.md b/docs/guide/rust/schema-evolution.md index 5886870759..2766641ca9 100644 --- a/docs/guide/rust/schema-evolution.md +++ b/docs/guide/rust/schema-evolution.md @@ -134,7 +134,9 @@ For typed ADT unions whose schema cases are unit or single-payload variants, forward-compatibility carrier. It cannot be the default variant, and the union must include at least one real schema case. The marker only selects the carrier and does not add an entry to the schema case table; schema cases use -non-negative IDs. +non-negative IDs. `UnknownCase` stores its payload as +`Arc<dyn Any + Send + Sync>`, so locally registered future payload types must be +thread-safe to be preserved as unknown cases. ### Enum Schema Evolution --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
