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
The following commit(s) were added to refs/heads/main by this push:
new fabaa4c73 π synced local 'docs/guide/' with remote 'docs/guide/'
fabaa4c73 is described below
commit fabaa4c7317c744b62e917860a6b404a916c7a28
Author: chaokunyang <[email protected]>
AuthorDate: Mon Oct 20 05:02:48 2025 +0000
π synced local 'docs/guide/' with remote 'docs/guide/'
---
docs/guide/rust_guide.md | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/docs/guide/rust_guide.md b/docs/guide/rust_guide.md
index b543f5207..0340b3ae5 100644
--- a/docs/guide/rust_guide.md
+++ b/docs/guide/rust_guide.md
@@ -750,6 +750,48 @@ assert_eq!(prefs.values().get(0), "en");
| Memory usage | Full object graph in memory | Only accessed fields
in memory |
| Suitable for | Small objects, full access | Large objects,
selective access |
+### 8. Thread-Safe Serialization
+
+Apache Foryβ’ Rust is fully thread-safe: `Fory` implements both `Send` and
`Sync`, so one configured instance can be shared across threads for concurrent
work. The internal read/write context pools are lazily initialized with
thread-safe primitives, letting worker threads reuse buffers without
coordination.
+
+```rust
+use fory::{Fory, Error};
+use fory::ForyObject;
+use std::sync::Arc;
+use std::thread;
+
+#[derive(ForyObject, Clone, Copy, Debug, PartialEq)]
+struct Item {
+ value: i32,
+}
+
+fn main() -> Result<(), Error> {
+ let mut fory = Fory::default();
+ fory.register::<Item>(1000)?;
+
+ let fory = Arc::new(fory);
+ let handles: Vec<_> = (0..8)
+ .map(|i| {
+ let shared = Arc::clone(&fory);
+ thread::spawn(move || {
+ let item = Item { value: i };
+ shared.serialize(&item)
+ })
+ })
+ .collect();
+
+ for handle in handles {
+ let bytes = handle.join().unwrap()?;
+ let item: Item = fory.deserialize(&bytes)?;
+ assert!(item.value >= 0);
+ }
+
+ Ok(())
+}
+```
+
+**Tip:** Perform registrations (such as `fory.register::<T>(id)`) before
spawning threads so every worker sees the same metadata. Once configured,
wrapping the instance in `Arc` is enough to fan out serialization and
deserialization tasks safely.
+
## π§ Supported Types
### Primitive Types
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]