Skip to content

Instantly share code, notes, and snippets.

@emidoots
Last active September 13, 2015 20:00
Show Gist options
  • Save emidoots/02d530b0965ef1275ff0 to your computer and use it in GitHub Desktop.
Save emidoots/02d530b0965ef1275ff0 to your computer and use it in GitHub Desktop.

Error:

$ cargo test
   Compiling fiz-math v0.0.12 (file:///home/stephen/Desktop/rust/mycrate)
src/lib.rs:4:13: 4:23 error: source trait is inaccessible
src/lib.rs:4     let v = x.to_foo().0;
                         ^~~~~~~~~~
src/lib.rs:4:13: 4:23 note: module `foo` is private
src/lib.rs:4     let v = x.to_foo().0;
                         ^~~~~~~~~~
error: aborting due to previous error
src/lib.rs:4:13: 4:23 error: source trait is inaccessible
src/lib.rs:4     let v = x.to_foo().0;
                         ^~~~~~~~~~
src/lib.rs:4:13: 4:23 note: module `foo` is private
src/lib.rs:4     let v = x.to_foo().0;
                         ^~~~~~~~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `fiz-math`.

To learn more, run the command again with --verbose.

src/lib.rs

pub mod mymod;

pub fn foobar<T: mymod::ToFoo>(x: T) {
    let v = x.to_foo().0;
}

src/mymod/mod.rs

mod foo;
pub use self::foo::{Foo, ToFoo};

src/mymod/foo.rs

pub trait ToFoo{
    fn to_foo(self) -> Foo;
}

pub struct Foo(pub f32);

impl ToFoo for Foo {
    fn to_foo(self) -> Foo { self }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment