# Week 05 Workshop

### Preparation

Before the workshop you should have watched the lectures. Some workshops have pre-workshop tasks which are optional, but useful. Completing labs before workshops is also optional (but may be useful)!

### Exercise: Workshop 5 - So.. Physics. Physics, Eh? Physics physics physics physics...

This week's workshop will explore Rust's trait system in more detail. You have been provided with code that does not use traits at all, which simulates the motion of bodies under gravity. Your job will be to refactor the code, and possibly to expand on it.

In the library you have been provided, there are two types of object defined in an enum. Planets do not move, but apply gravity to other objects. Asteroids move with a certain initial velocity, and are affected by gravity.

Since the enum is defined by the library, it is not possible to extend the library's behaviour to include different object types. In this task, you will modify the code so that it can support user-defined objects.

# Pre Workshop Work

The workshop code mostly re-uses the starter code from last week's workshop. We encourage you to try and copy your improved code into this week's starter code at the start of the workshop, or before.

# Using the Simulator

1. Refactor the code so that rather than taking a vec of enums, it takes a vec of Planets, and a vec of Asteroids. Once you are done, you should be able to entirely remove the ObjectType enum.
7. (extension) If you have time, try writing a trait which returns Option<&dyn GravitySource> or Option<&dyn GravityReceiver>. This will allow you to put your planets and asteroids back into a single Vec, and have objects which both are gravity sources and sinks.