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

Question about U on kdtre.rs #8

Closed
odarbelaeze opened this issue Oct 30, 2016 · 2 comments
Closed

Question about U on kdtre.rs #8

odarbelaeze opened this issue Oct 30, 2016 · 2 comments

Comments

@odarbelaeze
Copy link
Contributor

Hi,

I'm interested in space aware datastructures and just learning rust, I was wondering what does the U: AsRef<f64> means in the kdtree.rs file. Does it mean that there should be a generic parameter U that defaults to a slice of f64 items that are default implemented and functions like:

    pub fn nearest<F>(&self,
                      point: &[f64],
                      num: usize,
                      distance: &F)
                      -> Result<Vec<(f64, &T)>, ErrorKind>

can be implemented to use a type U rather than f64?

@Eh2406
Copy link
Contributor

Eh2406 commented Oct 30, 2016

It means that the structure can hold the "point" data in any type as long as it implements AsRef<[f64]> AsRef is from https://doc.rust-lang.org/std/convert/trait.AsRef.html
That is a type that that can be seean as a &[f64]. There are a lot of types that can be seen as a slice of f64. Vec or Arrays or slices or any custom types that chooses to implement the trait. Does that make sense?

@odarbelaeze
Copy link
Contributor Author

@Eh2406 oh, thanks, ye, just to see if I understood well, if I implement my own structure, with wathever fields, and then implement the trait, then I can store elements of that structure in the kdtree, sweet 😄

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