error not-serializable
What it means#
encode<T>, decode<T> and every other place that needs serialization (rpc parameters, topics, persisted actor fields) require T: Serializable. data and enum types are Serializable automatically when all their fields are; primitives, str, bytes, collections, tuples, T?, unions, distinct/refined types, time types, ActorRef<A> and secret<T> are too. Borrows, Rc, Arc, Task, stream, iter, functions, channels, Instant, String, ranges, interfaces and actors are not. The diagnostic names the offending component and the path to it.
Example#
use std.ser { encode }
data Shared {
counter: Rc<i32>
}
fn dump(s: &Shared) {
let b = encode(s) // <- not-serializable
}not-serializable
How to fix#
Replace the component with a serializable one (Rc<i32> with i32, String with str via freeze(), Instant with Time), or serialize a different type: a plain data copy of the persistent part. In a generic function add the bound: fn f<T: Serializable>(x: &T).