Skip to content

Commit

Permalink
format comments (bevyengine#1612)
Browse files Browse the repository at this point in the history
Uses the new unstable comment formatting features added to rustfmt.toml.
  • Loading branch information
cart committed Mar 11, 2021
1 parent be1c317 commit b17f8a4
Show file tree
Hide file tree
Showing 125 changed files with 894 additions and 599 deletions.
17 changes: 9 additions & 8 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ use bevy_utils::tracing::info_span;
#[allow(clippy::needless_doctest_main)]
/// Containers of app logic and data
///
/// App store the ECS World, Resources, Schedule, and Executor. They also store the "run" function of the App, which
/// by default executes the App schedule once. Apps are constructed using the builder pattern.
/// App store the ECS World, Resources, Schedule, and Executor. They also store the "run" function
/// of the App, which by default executes the App schedule once. Apps are constructed using the
/// builder pattern.
///
/// ## Example
/// Here is a simple "Hello World" Bevy app:
/// ```
///# use bevy_app::prelude::*;
///# use bevy_ecs::prelude::*;
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
///
///fn main() {
/// fn main() {
/// App::build()
/// .add_system(hello_world_system.system())
/// .run();
///}
/// }
///
///fn hello_world_system() {
/// fn hello_world_system() {
/// println!("hello world");
///}
/// }
/// ```
pub struct App {
pub world: World,
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_app/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ impl AppBuilder {
.add_system_to_stage(CoreStage::First, Events::<T>::update_system.system())
}

/// Inserts a resource to the current [App] and overwrites any resource previously added of the same type.
/// Inserts a resource to the current [App] and overwrites any resource previously added of the
/// same type.
pub fn insert_resource<T>(&mut self, resource: T) -> &mut Self
where
T: Component,
Expand All @@ -255,9 +256,9 @@ impl AppBuilder {
where
R: FromWorld + Send + Sync + 'static,
{
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed not to
// modify the map. However, we would need to be borrowing resources both mutably and immutably,
// so we would need to be extremely certain this is correct
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed
// not to modify the map. However, we would need to be borrowing resources both
// mutably and immutably, so we would need to be extremely certain this is correct
if !self.world_mut().contains_resource::<R>() {
let resource = R::from_world(self.world_mut());
self.insert_resource(resource);
Expand Down
49 changes: 30 additions & 19 deletions crates/bevy_app/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ enum State {
B,
}

/// An event collection that represents the events that occurred within the last two [Events::update] calls. Events can be cheaply read using
/// an [EventReader]. This collection is meant to be paired with a system that calls [Events::update] exactly once per update/frame. [Events::update_system]
/// is a system that does this. [EventReader]s are expected to read events from this collection at least once per update/frame. If events are not handled
/// within one frame/update, they will be dropped.
/// An event collection that represents the events that occurred within the last two
/// [Events::update] calls. Events can be cheaply read using an [EventReader]. This collection is
/// meant to be paired with a system that calls [Events::update] exactly once per update/frame.
/// [Events::update_system] is a system that does this. [EventReader]s are expected to read events
/// from this collection at least once per update/frame. If events are not handled within one
/// frame/update, they will be dropped.
///
/// # Example
/// ```
Expand Down Expand Up @@ -89,14 +91,16 @@ enum State {
///
/// # Details
///
/// [Events] is implemented using a double buffer. Each call to [Events::update] swaps buffers and clears out the oldest buffer.
/// [EventReader]s that read at least once per update will never drop events. [EventReader]s that read once within two updates might
/// still receive some events. [EventReader]s that read after two updates are guaranteed to drop all events that occurred before those updates.
/// [Events] is implemented using a double buffer. Each call to [Events::update] swaps buffers and
/// clears out the oldest buffer. [EventReader]s that read at least once per update will never drop
/// events. [EventReader]s that read once within two updates might still receive some events.
/// [EventReader]s that read after two updates are guaranteed to drop all events that occurred
/// before those updates.
///
/// The buffers in [Events] will grow indefinitely if [Events::update] is never called.
///
/// An alternative call pattern would be to call [Events::update] manually across frames to control when events are cleared. However
/// this complicates consumption
/// An alternative call pattern would be to call [Events::update] manually across frames to control
/// when events are cleared. However this complicates consumption
#[derive(Debug)]
pub struct Events<T> {
events_a: Vec<EventInstance<T>>,
Expand Down Expand Up @@ -180,7 +184,8 @@ impl<T> ManualEventReader<T> {
}
}

/// Like [`iter_with_id`](EventReader::iter_with_id) except not emitting any traces for read messages.
/// Like [`iter_with_id`](EventReader::iter_with_id) except not emitting any traces for read
/// messages.
fn internal_event_reader<'a, T>(
last_event_count: &mut usize,
events: &'a Events<T>,
Expand Down Expand Up @@ -232,7 +237,8 @@ fn internal_event_reader<'a, T>(

impl<'a, T: Component> EventReader<'a, T> {
/// Iterates over the events this EventReader has not seen yet. This updates the EventReader's
/// event counter, which means subsequent event reads will not include events that happened before now.
/// event counter, which means subsequent event reads will not include events that happened
/// before now.
pub fn iter(&mut self) -> impl DoubleEndedIterator<Item = &T> {
self.iter_with_id().map(|(event, _id)| event)
}
Expand All @@ -247,7 +253,8 @@ impl<'a, T: Component> EventReader<'a, T> {
}

impl<T: Component> Events<T> {
/// "Sends" an `event` by writing it to the current event buffer. [EventReader]s can then read the event.
/// "Sends" an `event` by writing it to the current event buffer. [EventReader]s can then read
/// the event.
pub fn send(&mut self, event: T) {
let event_id = EventId {
id: self.event_count,
Expand All @@ -273,15 +280,17 @@ impl<T: Component> Events<T> {
}
}

/// Gets a new [ManualEventReader]. This will ignore all events already in the event buffers. It will read all future events.
/// Gets a new [ManualEventReader]. This will ignore all events already in the event buffers. It
/// will read all future events.
pub fn get_reader_current(&self) -> ManualEventReader<T> {
ManualEventReader {
last_event_count: self.event_count,
_marker: PhantomData,
}
}

/// Swaps the event buffers and clears the oldest event buffer. In general, this should be called once per frame/update.
/// Swaps the event buffers and clears the oldest event buffer. In general, this should be
/// called once per frame/update.
pub fn update(&mut self) {
match self.state {
State::A => {
Expand Down Expand Up @@ -335,10 +344,11 @@ impl<T: Component> Events<T> {
}

/// Iterates over events that happened since the last "update" call.
/// WARNING: You probably don't want to use this call. In most cases you should use an `EventReader`. You should only use
/// this if you know you only need to consume events between the last `update()` call and your call to `iter_current_update_events`.
/// If events happen outside that window, they will not be handled. For example, any events that happen after this call and before
/// the next `update()` call will be dropped.
/// WARNING: You probably don't want to use this call. In most cases you should use an
/// `EventReader`. You should only use this if you know you only need to consume events
/// between the last `update()` call and your call to `iter_current_update_events`.
/// If events happen outside that window, they will not be handled. For example, any events that
/// happen after this call and before the next `update()` call will be dropped.
pub fn iter_current_update_events(&self) -> impl DoubleEndedIterator<Item = &T> {
match self.state {
State::A => self.events_a.iter().map(map_instance_event),
Expand All @@ -363,7 +373,8 @@ mod tests {
let event_1 = TestEvent { i: 1 };
let event_2 = TestEvent { i: 2 };

// this reader will miss event_0 and event_1 because it wont read them over the course of two updates
// this reader will miss event_0 and event_1 because it wont read them over the course of
// two updates
let mut reader_missed = events.get_reader();

let mut reader_a = events.get_reader();
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub enum CoreStage {
First,
/// Name of app stage responsible for performing setup before an update. Runs before UPDATE.
PreUpdate,
/// Name of app stage responsible for doing most app logic. Systems should be registered here by default.
/// Name of app stage responsible for doing most app logic. Systems should be registered here
/// by default.
Update,
/// Name of app stage responsible for processing the results of UPDATE. Runs after UPDATE.
PostUpdate,
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::any::Any;

/// A collection of Bevy App logic and configuration
///
/// Plugins use [AppBuilder] to configure an [App](crate::App). When an [App](crate::App) registers a plugin, the plugin's [Plugin::build] function is run.
/// Plugins use [AppBuilder] to configure an [App](crate::App). When an [App](crate::App) registers
/// a plugin, the plugin's [Plugin::build] function is run.
pub trait Plugin: Any + Send + Sync {
fn build(&self, app: &mut AppBuilder);
fn name(&self) -> &str {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_app/src/schedule_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ impl ScheduleRunnerSettings {
}
}

/// Configures an App to run its [Schedule](bevy_ecs::schedule::Schedule) according to a given [RunMode]
/// Configures an App to run its [Schedule](bevy_ecs::schedule::Schedule) according to a given
/// [RunMode]
#[derive(Default)]
pub struct ScheduleRunnerPlugin {}

Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ impl AssetServer {
let asset_loader = self.get_path_asset_loader(asset_path.path())?;
let asset_path_id: AssetPathId = asset_path.get_id();

// load metadata and update source info. this is done in a scope to ensure we release the locks before loading
// load metadata and update source info. this is done in a scope to ensure we release the
// locks before loading
let version = {
let mut asset_sources = self.server.asset_sources.write();
let source_info = match asset_sources.entry(asset_path_id.source_path_id()) {
Expand Down Expand Up @@ -282,7 +283,8 @@ impl AssetServer {
.await
.map_err(AssetServerError::AssetLoaderError)?;

// if version has changed since we loaded and grabbed a lock, return. theres is a newer version being loaded
// if version has changed since we loaded and grabbed a lock, return. theres is a newer
// version being loaded
let mut asset_sources = self.server.asset_sources.write();
let source_info = asset_sources
.get_mut(&asset_path_id.source_path_id())
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/filesystem_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crossbeam_channel::Receiver;
use notify::{Event, RecommendedWatcher, RecursiveMode, Result, Watcher};
use std::path::Path;

/// Watches for changes to assets on the filesystem. This is used by the `AssetServer` to reload them
/// Watches for changes to assets on the filesystem. This is used by the `AssetServer` to reload
/// them
pub struct FilesystemWatcher {
pub watcher: RecommendedWatcher,
pub receiver: Receiver<Result<Event>>,
Expand Down
12 changes: 8 additions & 4 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl HandleId {

/// A handle into a specific Asset of type `T`
///
/// Handles contain a unique id that corresponds to a specific asset in the [Assets](crate::Assets) collection.
/// Handles contain a unique id that corresponds to a specific asset in the [Assets](crate::Assets)
/// collection.
#[derive(Reflect)]
#[reflect(Component)]
pub struct Handle<T>
Expand Down Expand Up @@ -147,7 +148,8 @@ impl<T: Asset> Drop for Handle<T> {
fn drop(&mut self) {
match self.handle_type {
HandleType::Strong(ref sender) => {
// ignore send errors because this means the channel is shut down / the game has stopped
// ignore send errors because this means the channel is shut down / the game has
// stopped
let _ = sender.send(RefChange::Decrement(self.id));
}
HandleType::Weak => {}
Expand Down Expand Up @@ -233,7 +235,8 @@ unsafe impl<T: Asset> Sync for Handle<T> {}

/// A non-generic version of [Handle]
///
/// This allows handles to be mingled in a cross asset context. For example, storing `Handle<A>` and `Handle<B>` in the same `HashSet<HandleUntyped>`.
/// This allows handles to be mingled in a cross asset context. For example, storing `Handle<A>` and
/// `Handle<B>` in the same `HashSet<HandleUntyped>`.
#[derive(Debug)]
pub struct HandleUntyped {
pub id: HandleId,
Expand Down Expand Up @@ -299,7 +302,8 @@ impl Drop for HandleUntyped {
fn drop(&mut self) {
match self.handle_type {
HandleType::Strong(ref sender) => {
// ignore send errors because this means the channel is shut down / the game has stopped
// ignore send errors because this means the channel is shut down / the game has
// stopped
let _ = sender.send(RefChange::Decrement(self.id));
}
HandleType::Weak => {}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub enum AssetStage {
AssetEvents,
}

/// Adds support for Assets to an App. Assets are typed collections with change tracking, which are added as App Resources.
/// Examples of assets: textures, sounds, 3d models, maps, scenes
/// Adds support for Assets to an App. Assets are typed collections with change tracking, which are
/// added as App Resources. Examples of assets: textures, sounds, 3d models, maps, scenes
#[derive(Default)]
pub struct AssetPlugin;

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ unsafe impl Byteable for isize {}
unsafe impl Byteable for f32 {}
unsafe impl Byteable for f64 {}
unsafe impl Byteable for Vec2 {}
// NOTE: Vec3 actually takes up the size of 4 floats / 16 bytes due to SIMD. This is actually convenient because GLSL
// uniform buffer objects pad Vec3s to be 16 bytes.
// NOTE: Vec3 actually takes up the size of 4 floats / 16 bytes due to SIMD. This is actually
// convenient because GLSL uniform buffer objects pad Vec3s to be 16 bytes.
unsafe impl Byteable for Vec3 {}
unsafe impl Byteable for Vec4 {}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_core/src/float_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::{
ops::Neg,
};

/// A wrapper type that enables ordering floats. This is a work around for the famous "rust float ordering" problem.
/// By using it, you acknowledge that sorting NaN is undefined according to spec. This implementation treats NaN as the
/// "smallest" float.
/// A wrapper type that enables ordering floats. This is a work around for the famous "rust float
/// ordering" problem. By using it, you acknowledge that sorting NaN is undefined according to spec.
/// This implementation treats NaN as the "smallest" float.
#[derive(Debug, Copy, Clone, PartialOrd)]
pub struct FloatOrd(pub f32);

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_core/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ impl Labels {
}
}

/// Maintains a mapping from [Entity](bevy_ecs::prelude::Entity) ids to entity labels and entity labels to [Entities](bevy_ecs::prelude::Entity).
/// Maintains a mapping from [Entity](bevy_ecs::prelude::Entity) ids to entity labels and entity
/// labels to [Entities](bevy_ecs::prelude::Entity).
#[derive(Debug, Default)]
pub struct EntityLabels {
label_entities: HashMap<Cow<'static, str>, Vec<Entity>>,
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub struct CorePlugin;

#[derive(Debug, PartialEq, Eq, Clone, Hash, SystemLabel)]
pub enum CoreSystem {
/// Updates the elapsed time. Any system that interacts with [Time] component should run after this.
/// Updates the elapsed time. Any system that interacts with [Time] component should run after
/// this.
Time,
}

Expand All @@ -54,7 +55,8 @@ impl Plugin for CorePlugin {
.register_type::<Labels>()
.register_type::<Range<f32>>()
.register_type::<Timer>()
// time system is added as an "exclusive system" to ensure it runs before other systems in CoreStage::First
// time system is added as an "exclusive system" to ensure it runs before other systems
// in CoreStage::First
.add_system_to_stage(
CoreStage::First,
time_system.exclusive_system().label(CoreSystem::Time),
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_core/src/task_pool_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ impl TaskPoolThreadAssignmentPolicy {
/// this helper will do nothing.
#[derive(Clone)]
pub struct DefaultTaskPoolOptions {
/// If the number of physical cores is less than min_total_threads, force using min_total_threads
/// If the number of physical cores is less than min_total_threads, force using
/// min_total_threads
pub min_total_threads: usize,
/// If the number of physical cores is grater than max_total_threads, force using max_total_threads
/// If the number of physical cores is grater than max_total_threads, force using
/// max_total_threads
pub max_total_threads: usize,

/// Used to determine number of IO threads to allocate
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core/src/time/fixed_timestep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ impl System for FixedTimestep {
}

unsafe fn run_unsafe(&mut self, _input: Self::In, world: &World) -> Self::Out {
// SAFE: this system inherits the internal system's component access and archetype component access,
// which means the caller has ensured running the internal system is safe
// SAFE: this system inherits the internal system's component access and archetype component
// access, which means the caller has ensured running the internal system is safe
self.internal_system.run_unsafe((), world)
}

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_core/src/time/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use bevy_utils::Duration;
/// Tracks elapsed time. Enters the finished state once `duration` is reached.
///
/// Non repeating timers will stop tracking and stay in the finished state until reset.
/// Repeating timers will only be in the finished state on each tick `duration` is reached or exceeded, and can still be reset at any given point.
/// Repeating timers will only be in the finished state on each tick `duration` is reached or
/// exceeded, and can still be reset at any given point.
///
/// Paused timers will not have elapsed time increased.
#[derive(Clone, Debug, Default, Reflect)]
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod shader_defs;

use proc_macro::TokenStream;

/// Derives the FromResources trait. Each field must also implement the FromResources trait or this will fail. FromResources is
/// automatically implemented for types that implement Default.
/// Derives the FromResources trait. Each field must also implement the FromResources trait or this
/// will fail. FromResources is automatically implemented for types that implement Default.
#[proc_macro_derive(FromResources, attributes(as_crate))]
pub fn derive_from_resources(input: TokenStream) -> TokenStream {
resource::derive_from_resources(input)
Expand Down
Loading

0 comments on commit b17f8a4

Please sign in to comment.