Error (shared function has non-shared parameter typ)

I need to know , If there is a way , I can make some mutable attributes of a type sharable.
In easier words :

public type Post = {
    var pid : Nat; 
    uid : Nat; 
    xid : Nat;
    ppid : Nat;
    var video : Nat;
...................
  };

In above type , I made two attributes mutable by adding var , so that i can change them inside a function body (Got this solution from a forum topic) , but when i am passing this Post value as a prop or trying to return it in the function say:

public query func get(xId : Nat) : async [Types.Post]{
        ..................
        return [];
    };

I am getting error as :

** shared function has non-shared return type**

Is there any other way , to make some properties of type Post mutable , what am i missing?

:::::::::::::
Also can we declare a triemap as Stable var or not ?

1 Like

The short answer is no, shared types, used in messaging, cannot contain mutable fields or arrays.

A TrieMap object cannot be stable, because some of its fields are functions, but you can use the encapsulated Trie as a stale variable, because it is just first order data. However, you need to make sure you don’t change the definition of the hash function used between upgrades.

2 Likes