Skip to content

Having trouble using std::rc::Rc values within a Mutation object. #110

@ruseinov

Description

@ruseinov

Here's an example:

fn ipfs_client(ctx: &Context<'_>) -> Result<IpfsClient, InvalidUri> {
    let app_data = ctx.data::<AppData>();
    IpfsClient::from_str(&app_data.ipfs_url)
}
    async fn create_asset(
        &self,
        ctx: &Context<'_>,
        file: Upload,
    ) -> FieldResult<Asset> {

        if true {
            let reader = File::open(file.path)?;

            let ipfs_client = ipfs_client(ctx)?;

            let resp = ipfs_client.add(reader).await.map_err(|err| {
                ErrorKind::Fatal(format!("Failed to add a file to IPFS: {:?}", err))
            })?;

            ipfs_hash = resp.hash;
        }
}

The Object macro on MutationRoot

#[Object]
impl MutationRoot {

Would throw an error:

69  | #[Object]
    | ^^^^^^^^^ future returned by `__resolve_field` is not `Send`
    |
    = help: within `impl core::future::future::Future`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<awc::ClientConfig>`

and also

   | `std::rc::Rc<std::cell::RefCell<actix_http::h1::payload::Inner>>` cannot be sent between threads safely

For the result of the add operation.

For the record: I'm not trying to pass the ipfs_client around, I instantiate it when it's needed, get a result and throw it away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions