Reference type for lazy access to a remote data structure

Hello there,
I am building a web app using Rust and WASM, and I would like to profit as much as possible from using the same APIs both on the client and the server. I have been using REST so far, but I was wondering if we can do better. Would it be possible to request some kind of reference from the server, which acts just like a Rust reference, but processes HTTP communication under the hood? Is there anything comparable already available today?
I am imagining something like this:

// Server side
listen(|request| {
    let ref_request: HttpReferenceRequest = request.body().try_into().unwrap();
        match ref_request.table_name().as_str() {
            "users" => {
                DATABASE.users().reference(ref_request.entry_id()) as HttpReference<User>
            _ => Err("Unknown table!"),
// Client side
let user_reference: HttpReference<User> =
                    Id<User>::from(user_id) // get reference for User by id
    .expect("Fetch failed!")
    .expect("Unable to convert to reference!");

assert_eq!(user_reference.get().unwrap(), User { name: "User from Server", ... });
user_reference.set_name("New Name".to_string()).expect("Failed to update remote entry!"); 

Does this make sense? I like the idea of a data type for lazy remote access, but I am not sure if it is as simple or useful as I think. I would very much like to hear some thoughts on this.

You could certainly define a reference-like type with a custom get method.

Yes, I was hoping there was already a crate for this. But maybe I can make one myself, depending on how easily I can abstract over the browser and server API.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.