Feature Request
When to use Rc/Arc/Weak:
- Rc (Reference Counted)
- Use when: You need multiple parts of your single-threaded program to share ownership of a value, and you want the value to be deallocated only when the last owner is gone.
- Example: A tree structure where different nodes might need to refer to the same parent node.
- Arc (Atomic Reference Counted)- Use when: You need multiple threads to share ownership of data. It's the thread-safe version of Rc.
- Example: Multiple threads need to access and read the same immutable configuration data.
- Weak (Weak Reference):
- Use when: You have a reference cycle between Rc or Arc pointers that would cause a memory leak. A Weak pointer doesn't count towards the strong reference count, allowing the data to be deallocated even if Weak pointers still exist.
- How it works: To access the data, a Weak reference must be "upgraded" to a strong Rc or Arc reference. If the data has already been deallocated, the upgrade will fail, returning a null pointer, which is how you check for validity.
- Example: In a doubly linked list, where each node has a next pointer (strong) and a prev pointer (weak) to avoid a circular dependency that would prevent the nodes from being deallocated
Object graph is common in languages like java/python/go, by using Rc/Arc/Weak, we can implement similiar functionalities in rust. Fory needs to support Rc/Arc/Weak serialization.
Is your feature request related to a problem? Please describe
No response
Describe the solution you'd like
Like we did in java/python, we can implement a RefResolver in rust, which track reference for Rc/Arc/Weak by using a Map. At deserialization, we can use a Vec<Ref> to hold those reference to rebuild the reference relationship.
Ref can be defined as:
enum Ref {
RcRef(Box<dyn Any>),
ArcRef(Box<dyn Any>)
}
https://github.com/apache/fory/blob/main/java/fory-core/src/main/java/org/apache/fory/resolver/MapRefResolver.java can be used an example for implementation in rust.
Describe alternatives you've considered
No response
Additional context
No response
Feature Request
When to use
Rc/Arc/Weak:Object graph is common in languages like java/python/go, by using
Rc/Arc/Weak, we can implement similiar functionalities in rust. Fory needs to supportRc/Arc/Weakserialization.Is your feature request related to a problem? Please describe
No response
Describe the solution you'd like
Like we did in java/python, we can implement a
RefResolverin rust, which track reference forRc/Arc/Weakby using a Map. At deserialization, we can use aVec<Ref>to hold those reference to rebuild the reference relationship.Refcan be defined as:https://github.com/apache/fory/blob/main/java/fory-core/src/main/java/org/apache/fory/resolver/MapRefResolver.java can be used an example for implementation in rust.
Describe alternatives you've considered
No response
Additional context
No response