Common features not visible in an external module
I have the following code:
pub trait Osm<T> {
fn get_points(&self) -> Vec<Point<T>>;
}
#[deriving(Show, PartialEq, Clone)]
pub struct Point<T> {
pub lat: T,
pub lon: T,
}
#[deriving(Show, PartialEq, Clone)]
pub struct Node<T> {
pub point: Point<T>,
}
impl<T: Clone> Osm<T> for Node<T> {
fn get_points(&self) -> Vec<Point<T>> {
return vec![self.point.clone()];
}
}
When I put this code in the main menu and call:
let b = Node { point: Point { lat: 10i64, lon: 12i64 }};
println!("{}", b.get_points());
everything works fine.
But when I put it in another module, we get the following error:
/prj/src/main.rs:64:22: 64:34 error: type `osm::test::Node<i64>` does not implement any method in scope named `get_points`
/prj/src/main.rs:64 println!("{}", b.get_points());
^~~~~~~~~~~~
error: aborting due to previous error
I'm a little confused as to why it doesn't work, maybe it makes a private method because for main everything works fine, but when I try to use pub
keywords it shows unnecessary visibility qualifier
build error . Can I use similarities for an external module?
source to share
To use a characteristic method in another module, you first need a use
characteristic.
So it use osm::test::Osm;
should work. This is the only case where the operator is use
importing functionality and not just making the identifier available.
Also, methods do not need to be explicitly pub
for pub trait
, since exporting that object will export methods.
source to share