Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume a paginated restful - faulty #620

Open
mgabs opened this issue Nov 30, 2020 · 4 comments · May be fixed by #710
Open

Consume a paginated restful - faulty #620

mgabs opened this issue Nov 30, 2020 · 4 comments · May be fixed by #710

Comments

@mgabs
Copy link

mgabs commented Nov 30, 2020

Link - https://rust-lang-nursery.github.io/rust-cookbook/web/clients/apis.html#consume-a-paginated-restful-api

When i run the example at retrieves the dependencies however, the crate_id is populated with the source crate name..
example.

reverse dependency: Dependencies {
    id: 1512403,
    version_id: 260859,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1171189,
    version_id: 214959,
    crate_id: "serde",
    req: "^1",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1679135,
    version_id: 282866,
    crate_id: "serde",
    req: "^1.0",
    optional: true,
}
reverse dependency: Dependencies {
    id: 1513367,
    version_id: 260957,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1509548,
    version_id: 260570,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1510400,
    version_id: 260674,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1857747,
    version_id: 306796,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 221948,
    version_id: 56468,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1005933,
    version_id: 191390,
    crate_id: "serde",
    req: "^1.0.101",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1718978,
    version_id: 288126,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 201348,
    version_id: 52572,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 502365,
    version_id: 108551,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 734888,
    version_id: 149808,
    crate_id: "serde",
    req: "^1.0.91",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1511500,
    version_id: 260772,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 656418,
    version_id: 135925,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1482273,
    version_id: 257090,
    crate_id: "serde",
    req: "^1.0.114",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1197240,
    version_id: 218162,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1567895,
    version_id: 268290,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1341760,
    version_id: 237984,
    crate_id: "serde",
    req: "^1.0.106",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1510609,
    version_id: 260697,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1513547,
    version_id: 260972,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 682833,
    version_id: 140883,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 1368898,
    version_id: 241717,
    crate_id: "serde",
    req: "^1.0.107",
    optional: true,
}
reverse dependency: Dependencies {
    id: 619659,
    version_id: 129517,
    crate_id: "serde",
    req: "^1.0",
    optional: false,
}
reverse dependency: Dependencies {
    id: 989622,
    version_id: 188910,
    crate_id: "serde",
    req: "^1.0.101",
    optional: false,
}
@AndyGauge
Copy link
Collaborator

Yep, that's what the api is returning
https://crates.io/api/v1/crates/error-chain/reverse_dependencies
I thing that's strange field name for the name of the crate.

@mgabs
Copy link
Author

mgabs commented Dec 1, 2020

Sorry, I don't get your comment.
What I am saying is the struct is storing the source crate as a member of ReverDep structs.
Which is a faulty behaviour.

Further, I couldn't consume elements from the iter.
same example:

   for dep in ReverseDependencies::of("tokio")? {
        // println!("reverse dependency: {:#?}", dep?);
        println!("{:#?}", dep?.crate_id);
        println!("{:#?}", dep?.req);
    }

error[E0382]: use of moved value: `dep`
   --> src/main.rs:109:27
    |
106 |     for dep in ReverseDependencies::of("tokio")? {
    |         --- move occurs because `dep` has type `std::result::Result<Dependencies, reqwest::Error>`, which does not implement the `Copy` trait
107 |         // println!("reverse dependency: {:#?}", dep?);
108 |         println!("{:#?}", dep?.crate_id);
    |                           ---- `dep` moved due to this method call
109 |         println!("{:#?}", dep?.req);
    |                           ^^^ value used here after move
    |
note: this function consumes the receiver `self` by taking ownership of it, which moves `dep`

What is the best way to address that ?

@AndyGauge
Copy link
Collaborator

I mean if you go to the link I provided you will see this:
{"dependencies":[{"id":987053,"version_id":188578,"crate_id":"error-chain","req":"^0.12","optional":false,"default_features":false,"features":[],"target":null,"kind":"normal","downloads":3135857}

The API returns crate_id = crate name

"crate_id":"error-chain"

error[E0382]: use of moved value: dep
When you follow dep by the ? you are performing an operation on it. You can do let depends=dep?; and then println! it twice

@mgabs
Copy link
Author

mgabs commented Dec 1, 2020 via email

@AndyGauge AndyGauge linked a pull request Nov 30, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants