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

Cannot declare a satisfiable feed reference #69

Open
telamon opened this issue May 12, 2019 · 2 comments
Open

Cannot declare a satisfiable feed reference #69

telamon opened this issue May 12, 2019 · 2 comments

Comments

@telamon
Copy link

telamon commented May 12, 2019

Question

Your Environment

Software Version(s)
hypercore 0.9.0
Rustc rustc 1.34.1 (fc50f328b 2019-04-24)
Operating System linux

Question

So I'm not sure if I should ask this question here. I have tried to find help elsewhere but writing here as a last-resort.
I'm new to rust and I have been picking up the language at a steady pace.
But there's one issue that I've been struggling with to the point of insanity.

How do you store a hypercore::Feed in a struct or define a function that can take a feed as a parameter?

// What is the correct type declaration for feed? 
pub struct MyStruct {
  m_feed: Feed<RandomAccess>,
}; 

pub fn (a_feed: &Feed<RandomAccess>) { ... }

// Or even slightly modifying the example from the docs:
let path = PathBuf::from("./my-first-dataset");
let mut feed: TYPE_DECLARATION = Feed::new(&path).unwrap();

I've literally spent a week trying all kinds of exotic declaration to satisfy the compiler traits, but to no avail..

Again humble apologies for asking this here, please help!

@yoshuawuyts
Copy link
Contributor

@telamon no worries, it's always okay to ask (:

Getting a better idea of what you're looking at would be helpful. I'm not sure what you're running into. Screenshots would be good, text output would be better, a git repo that can be cloned and run to reproduce your error would be best.

Thanks!

@telamon
Copy link
Author

telamon commented May 15, 2019

@yoshuawuyts Thank you for the reply.
Sorry if my question was a bit unclear, essentially I'd like to know how to define a struct capable of holding a Feed or a method that could take a reference to a Feed.
Due to the design of the RandomAccess trait I cannot figure out how to declare my struct letalone define a variable that will be able to hold it without using the automatic type declaration.

Here is an example I ended up with following compiler errors:

use hypercore::Feed;
use random_access::RandomAccess;
use std::path::PathBuf;

#[test]
fn it_works() {
    let storage_path = PathBuf::from("/tmp/a");
    let mut feed: Feed<RandomAccess<Error = failure::Error>> = hypercore::Feed::new(&storage_path).unwrap();
    //            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   // I simply can't figure out the correct type format to satisfy the compiler.
}

The above snippet produces the following error:

   Compiling ciphercore v0.1.0 (/home/telamon/lpro/hyper-rs/ciphercore)
error[E0277]: the size for values of type `dyn random_access_storage::RandomAccess<Error=failure::error::Error>` cannot be known at compilation time
  --> tests/test.rs:10:19
   |
10 |     let mut feed: Feed<RandomAccess<Error = failure::Error>> = hypercore::Feed::new(&storage_path).unwrap();
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `dyn random_access_storage::RandomAccess<Error=failure::error::Error>`
   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = note: required by `hypercore::Feed`

Omitting Error = failure::Error as argument to RandomAccess<> makes the compiler complain about a missing argument, just like omitting RandomAccess from from Feed<> produces the same compiler complaint.

Ultimately I would just like to define a struct with a feed...

pub struct MyStruct {
 a_feed: ??Type??
}

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

No branches or pull requests

2 participants