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

IntelliSense shows all the methods #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

T1mors
Copy link
Collaborator

@T1mors T1mors commented May 28, 2021

The Issue was that VSCodes Intellisense does not recognize e.g. .vertex_count() if you use it directly on e.g. SwEnsemble.vertex_count() but only shows the function if you use it like this SwEnsemble.graph().vertex_count(), although both work and give the same output.

So I think the issue is, that when you use SwEnsemble.vertex_count() it uses the function from net_ensemble\traits\graph_trait -> trait MeasurableGraphQuantities. And in the end of the graph_trait file those Quantities gets implemented for all Ensembles like this impl<T, A, E> MeasurableGraphQuantities<GenericGraph<T, A>> for E

But it does not get directly implemented for SwEnsemble, but only on a "passive" way for all E. So the only solution is to implement MeasurableGraphQuantities in the net_ensemble\sw.rs file and for SwEnsemble directly. Then VSCode can look first for all the implemented traits on SwEnsemble in sw.rs and finds the .vertex_count defintion.

I did this implementation for all the Ensembles. You do not have to merge this, but I wanted to show you my results when I dug into the code.

Maybe it is a good way to impl it directly in these files so everyone can see that SwEnsemble has these methods. But on the otherhand it is duplicated code because we get the same result with a .graph().vertex_count() call already and both function calls lead to the exact same underlying structure. The .graph().vertex_count() call refers to the GenericGraph struct and that struct already implements all the functions the trait MeasurableGraphQuantities does too.

Just wanted to share this :D

Here some code to try the IntelliSense out.

use net_ensembles::{
    rand::SeedableRng, BAensemble, EmptyNode, ErEnsembleC, ErEnsembleM, SwEnsemble,
};
use rand_pcg::Pcg64;

fn main() {
    let rng = Pcg64::seed_from_u64(75676525);
    let sw_ensemble = SwEnsemble::<EmptyNode, Pcg64>::new(5, 0.1, rng);
    println!("SwEnsemble.vertex_count()");
    println!("{}", sw_ensemble.vertex_count());
    println!("SwEnsemble.graph().vertex_count()");
    println!("{}", sw_ensemble.graph().vertex_count());

    let rng = Pcg64::seed_from_u64(75676525);
    let er_ensemblec = ErEnsembleC::<EmptyNode, Pcg64>::new(5, 0.1, rng);
    println!("ErEnsembleC.vertex_count()");
    println!("{}", er_ensemblec.vertex_count());
    println!("ErEnsembleC.graph().vertex_count()");
    println!("{}", er_ensemblec.graph().vertex_count());

    let rng = Pcg64::seed_from_u64(75676525);
    let er_ensemblem = ErEnsembleM::<EmptyNode, Pcg64>::new(5, 5, rng);
    println!("ErEnsembleM.vertex_count()");
    println!("{}", er_ensemblem.vertex_count());
    println!("ErEnsembleM.graph().vertex_count()");
    println!("{}", er_ensemblem.graph().vertex_count());

    let rng = Pcg64::seed_from_u64(75676525);
    let ba_ensemble = BAensemble::<EmptyNode, Pcg64>::new(5, rng, 5, 5);
    println!("BAEnsemble.vertex_count()");
    println!("{}", ba_ensemble.vertex_count());
    println!("BAEnsemble.graph().vertex_count()");
    println!("{}", ba_ensemble.graph().vertex_count());
}```

Found the underlying issue, that IntelliSense does not recognize .vertex_count method with the call e.g. SwEnsemble.vertex_count() but does so with SwEnsemble.graph().vertex_count()
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

Successfully merging this pull request may close these issues.

1 participant