Skip to content

Who adds .system() to hello_world.system()? #1137

Answered by smokku
abitrolly asked this question in Q&A
Discussion options

You must be logged in to vote

Simplifying things a bit.

In Bevy there is a code like this:

impl IntoSystem for FnMut()
{
    fn system(mut self) -> FuncSystem {
        ...
    }
}

Which implements IntoSystem for a function without parameters (FnMut()).

When compiler sees hello_world.system() it does something like this:

  1. Ok - the dot means I need to call a method.
  2. What is the type of the thing left to dot (hello_world)? It is FnMut().
  3. Do I have any trait in scope that defines what is the right of the dot (the system() method) on FnMut()? Yes - the IntoSystem trait.
  4. Do I have an implementation of that trait available? Yes (see above).
  5. Ok. Let's generate a call to that function passing it the thing on the left of dot.

T…

Replies: 4 comments 15 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@DJMcNab
Comment options

@abitrolly
Comment options

@smokku
Comment options

@DJMcNab
Comment options

Comment options

You must be logged in to vote
11 replies
@abitrolly
Comment options

@abitrolly
Comment options

@DJMcNab
Comment options

@smokku
Comment options

@DJMcNab
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants