ferristseng / rust-ipfs-api

IPFS HTTP client in Rust
Apache License 2.0
246 stars 68 forks source link

When I use documents and examples, I find it can't help me #101

Closed Jzow closed 2 years ago

Jzow commented 2 years ago

When I want to get a piece of text through hash, I can't print it out

    #[tokio::test]
    async fn get_hash_info() {
        let client = IpfsClient::from_str("http://127.0.0.1:5001").unwrap();
        let hash = "QmWsJn7mNcqZULbM2arPjywKX8evwNFAznKPLzg1oFZyfg";

        let res = client
            .dag_get(hash)
            .map_ok(|chunk| chunk.to_vec())
            .try_concat();

        println!("{:?}", res);
    }

error:

no method named `map_ok` found for struct `Box<(dyn futures_core::stream::Stream<Item = Result<actix_web::web::Bytes, ipfs_api_backend_actix::Error>> + Unpin + 'static)>` in the current scope

items from traits can only be used if the trait is in scoperustc[E0599](https://doc.rust-lang.org/error-index.html#E0599)
mod.rs(200, 8): the method is available for `Box<(dyn futures_core::stream::Stream<Item = Result<actix_web::web::Bytes, ipfs_api_backend_actix::Error>> + Unpin + 'static)>` here

ipfs_api.rs(38, 5): the following trait is implemented but not in scope; perhaps add a `use` for it:: `use futures_util::stream::try_stream::TryStreamExt;

I also try to use object_get method. I can't find the relevant example

Jzow commented 2 years ago

This is not very friendly for new developers

kallisti5 commented 2 years ago

If you actually get it working, the errors are also super unhelpful...


use http::Uri;
use ipfs_api_backend_hyper::{IpfsApi, IpfsClient, TryFromUri};
use std::io::Cursor;

#[tokio::main]
async fn main() {
        let uri = "http://192.168.1.80:5001/".parse::<Uri>().unwrap();
        let client = IpfsClient::build_with_base_uri(uri);
        match client.version().await {
                Ok(version) => eprintln!("version: {:?}", version.version),
                Err(e) => eprintln!("error getting version: {}", e),
        };
        match client.pubsub_pub("test", Cursor::new("TEST!")).await {
                Ok(_) => println!("OK!"),
                Err(e) => println!("error: {}", e),
        };
}
./target/debug/ipfs-mqtt 
error getting version: ipfs client error `api returned an unknown error ```
error: ipfs client error `api returned an unknown error ```