Skip to content

Commit

Permalink
rustfmt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Jul 28, 2020
1 parent 6dadf34 commit 7212b70
Show file tree
Hide file tree
Showing 58 changed files with 210 additions and 61 deletions.
1 change: 1 addition & 0 deletions crates/bevy_asset/src/load_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ where
.send(asset_result)
.expect("loaded asset should have been sent");
}

fn extensions(&self) -> &[&str] {
self.loader.extensions()
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_audio/src/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl AssetLoader<AudioSource> for Mp3Loader {
bytes: Arc::new(bytes),
})
}

fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["mp3"];
EXTENSIONS
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_core/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl Bytes for Mat4 {
let array = self.to_cols_array();
array.write_bytes(buffer);
}

fn byte_len(&self) -> usize {
std::mem::size_of::<Self>()
}
Expand All @@ -123,6 +124,7 @@ where
val.write_bytes(buffer)
}
}

fn byte_len(&self) -> usize {
self.as_ref().map_or(0, |val| val.byte_len())
}
Expand All @@ -149,6 +151,7 @@ where
let bytes = self.as_slice().as_bytes();
buffer[0..self.byte_len()].copy_from_slice(bytes)
}

fn byte_len(&self) -> usize {
self.as_slice().as_bytes().len()
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_core/src/float_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl Hash for FloatOrd {

impl Neg for FloatOrd {
type Output = FloatOrd;

fn neg(self) -> Self::Output {
FloatOrd(-self.0)
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_core/src/time/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl Timer {
..Default::default()
}
}

pub fn new(duration: Duration) -> Self {
Timer {
duration: duration.as_secs_f32(),
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_ecs/hecs/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl<'a, T: Component> Drop for Ref<'a, T> {

impl<'a, T: Component> Deref for Ref<'a, T> {
type Target = T;

fn deref(&self) -> &T {
unsafe { self.target.as_ref() }
}
Expand Down Expand Up @@ -153,6 +154,7 @@ impl<'a, T: Component> Drop for RefMut<'a, T> {

impl<'a, T: Component> Deref for RefMut<'a, T> {
type Target = T;

fn deref(&self) -> &T {
unsafe { self.target.as_ref() }
}
Expand Down
25 changes: 24 additions & 1 deletion crates/bevy_ecs/hecs/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,22 @@ impl Query for Entity {

impl<'a> Fetch<'a> for EntityFetch {
type Item = Entity;

#[inline]
fn access(_archetype: &Archetype) -> Option<Access> {
Some(Access::Iterate)
}

#[inline]
fn borrow(_archetype: &Archetype) {}

#[inline]
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
Some(EntityFetch(NonNull::new_unchecked(
archetype.entities().as_ptr().add(offset),
)))
}

#[inline]
fn release(_archetype: &Archetype) {}

Expand Down Expand Up @@ -125,11 +129,13 @@ impl<'a, T: Component> Fetch<'a> for FetchRead<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow::<T>();
}

unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype
.get::<T>()
.map(|x| Self(NonNull::new_unchecked(x.as_ptr().add(offset))))
}

fn release(archetype: &Archetype) {
archetype.release::<T>();
}
Expand Down Expand Up @@ -161,6 +167,7 @@ unsafe impl<T: Component> Sync for Mut<'_, T> {}

impl<'a, T: Component> Deref for Mut<'a, T> {
type Target = T;

#[inline]
fn deref(&self) -> &T {
self.value
Expand Down Expand Up @@ -195,6 +202,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMut<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow_mut::<T>();
}

unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype
.get_with_mutated::<T>()
Expand All @@ -205,6 +213,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMut<T> {
)
})
}

fn release(archetype: &Archetype) {
archetype.release_mut::<T>();
}
Expand All @@ -229,6 +238,7 @@ pub struct Mutated<'a, T> {

impl<'a, T: Component> Deref for Mutated<'a, T> {
type Target = T;

#[inline]
fn deref(&self) -> &T {
self.value
Expand Down Expand Up @@ -256,6 +266,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMutated<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow::<T>();
}

unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype
.get_with_mutated::<T>()
Expand All @@ -266,6 +277,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMutated<T> {
)
})
}

fn release(archetype: &Archetype) {
archetype.release::<T>();
}
Expand All @@ -291,6 +303,7 @@ pub struct Added<'a, T> {

impl<'a, T: Component> Deref for Added<'a, T> {
type Target = T;

#[inline]
fn deref(&self) -> &T {
self.value
Expand Down Expand Up @@ -318,6 +331,7 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow::<T>();
}

unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype.get_with_added::<T>().map(|(components, added)| {
Self(
Expand All @@ -326,6 +340,7 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded<T> {
)
})
}

fn release(archetype: &Archetype) {
archetype.release::<T>();
}
Expand All @@ -351,6 +366,7 @@ pub struct Changed<'a, T> {

impl<'a, T: Component> Deref for Changed<'a, T> {
type Target = T;

#[inline]
fn deref(&self) -> &T {
self.value
Expand Down Expand Up @@ -390,6 +406,7 @@ impl<'a, T: Component> Fetch<'a> for FetchChanged<T> {
)
})
}

fn release(archetype: &Archetype) {
archetype.release::<T>();
}
Expand Down Expand Up @@ -422,9 +439,11 @@ impl<'a, T: Fetch<'a>> Fetch<'a> for TryFetch<T> {
fn borrow(archetype: &Archetype) {
T::borrow(archetype)
}

unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
Some(Self(T::get(archetype, offset)))
}

fn release(archetype: &Archetype) {
T::release(archetype)
}
Expand Down Expand Up @@ -478,12 +497,14 @@ impl<'a, T: Component, F: Fetch<'a>> Fetch<'a> for FetchWithout<T, F> {
fn borrow(archetype: &Archetype) {
F::borrow(archetype)
}

unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
if archetype.has::<T>() {
return None;
}
Some(Self(F::get(archetype, offset)?, PhantomData))
}

fn release(archetype: &Archetype) {
F::release(archetype)
}
Expand Down Expand Up @@ -539,12 +560,14 @@ impl<'a, T: Component, F: Fetch<'a>> Fetch<'a> for FetchWith<T, F> {
fn borrow(archetype: &Archetype) {
F::borrow(archetype)
}

unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
if !archetype.has::<T>() {
return None;
}
Some(Self(F::get(archetype, offset)?, PhantomData))
}

fn release(archetype: &Archetype) {
F::release(archetype)
}
Expand Down Expand Up @@ -693,8 +716,8 @@ impl<'w, Q: Query> Drop for QueryBorrow<'w, Q> {
}

impl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q> {
type Item = <Q::Fetch as Fetch<'q>>::Item;
type IntoIter = QueryIter<'q, 'w, Q>;
type Item = <Q::Fetch as Fetch<'q>>::Item;

fn into_iter(self) -> Self::IntoIter {
self.iter()
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_ecs/hecs/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ impl Default for World {
impl<'a> IntoIterator for &'a World {
type IntoIter = Iter<'a>;
type Item = (Entity, EntityRef<'a>);

fn into_iter(self) -> Iter<'a> {
self.iter()
}
Expand Down Expand Up @@ -700,6 +701,7 @@ unsafe impl Sync for Iter<'_> {}

impl<'a> Iterator for Iter<'a> {
type Item = (Entity, EntityRef<'a>);

fn next(&mut self) -> Option<Self::Item> {
loop {
match self.current {
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_ecs/src/resource/resource_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ unsafe impl<T: Component> Sync for Res<'_, T> {}

impl<'a, T: Component> Deref for Res<'a, T> {
type Target = T;

fn deref(&self) -> &T {
self.value
}
Expand All @@ -64,6 +65,7 @@ unsafe impl<T: Component> Sync for ResMut<'_, T> {}

impl<'a, T: Component> Deref for ResMut<'a, T> {
type Target = T;

fn deref(&self) -> &T {
unsafe { &*self.value }
}
Expand Down Expand Up @@ -100,6 +102,7 @@ impl<'a, T: Component + FromResources> UnsafeClone for Local<'a, T> {

impl<'a, T: Component + FromResources> Deref for Local<'a, T> {
type Target = T;

fn deref(&self) -> &T {
unsafe { &*self.value }
}
Expand Down Expand Up @@ -142,6 +145,7 @@ pub struct FetchResourceRead<T>(NonNull<T>);

impl<'a, T: Component> FetchResource<'a> for FetchResourceRead<T> {
type Item = Res<'a, T>;

unsafe fn get(resources: &'a Resources, _system_id: Option<SystemId>) -> Self::Item {
Res::new(resources.get_unsafe_ref::<T>(ResourceIndex::Global))
}
Expand Down Expand Up @@ -169,6 +173,7 @@ pub struct FetchResourceWrite<T>(NonNull<T>);

impl<'a, T: Component> FetchResource<'a> for FetchResourceWrite<T> {
type Item = ResMut<'a, T>;

unsafe fn get(resources: &'a Resources, _system_id: Option<SystemId>) -> Self::Item {
ResMut::new(resources.get_unsafe_ref::<T>(ResourceIndex::Global))
}
Expand Down Expand Up @@ -202,6 +207,7 @@ pub struct FetchResourceLocalMut<T>(NonNull<T>);

impl<'a, T: Component + FromResources> FetchResource<'a> for FetchResourceLocalMut<T> {
type Item = Local<'a, T>;

unsafe fn get(resources: &'a Resources, system_id: Option<SystemId>) -> Self::Item {
let id = system_id.expect("Local<T> resources can only be used by systems");
Local {
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/schedule/parallel_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl ParallelExecutor {
..Default::default()
}
}

pub fn prepare(&mut self, schedule: &mut Schedule, world: &World) {
let schedule_generation = schedule.generation();
let schedule_changed = schedule_generation != self.last_schedule_generation;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/system/into_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ where
fn initialize(&mut self, resources: &mut Resources) {
(self.init_func)(resources);
}

fn id(&self) -> SystemId {
self.id
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl AssetLoader<Mesh> for GltfLoader {
let mesh = load_gltf(asset_path, bytes)?;
Ok(mesh)
}

fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["gltf"];
EXTENSIONS
Expand Down
22 changes: 16 additions & 6 deletions crates/bevy_math/src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::ops::{Add, AddAssign};
use glam::Vec2;
use std::ops::{Add, AddAssign};

#[derive(Copy, Clone, PartialEq, Debug)]
pub struct Size<T=f32> {
pub struct Size<T = f32> {
pub width: T,
pub height: T,
}
Expand Down Expand Up @@ -31,7 +31,10 @@ pub struct Rect<T> {
}

impl<T> Rect<T> {
pub fn all(value: T) -> Self where T: Clone{
pub fn all(value: T) -> Self
where
T: Clone,
{
Rect {
left: value.clone(),
right: value.clone(),
Expand All @@ -52,8 +55,12 @@ impl<T: Default> Default for Rect<T> {
}
}

impl<T> Add<Vec2> for Size<T> where T: Add<f32, Output=T> {
impl<T> Add<Vec2> for Size<T>
where
T: Add<f32, Output = T>,
{
type Output = Size<T>;

fn add(self, rhs: Vec2) -> Self::Output {
Self {
width: self.width + rhs.x(),
Expand All @@ -62,9 +69,12 @@ impl<T> Add<Vec2> for Size<T> where T: Add<f32, Output=T> {
}
}

impl<T> AddAssign<Vec2> for Size<T> where T: AddAssign<f32> {
impl<T> AddAssign<Vec2> for Size<T>
where
T: AddAssign<f32>,
{
fn add_assign(&mut self, rhs: Vec2) {
self.width += rhs.x();
self.height += rhs.y();
}
}
}
Loading

0 comments on commit 7212b70

Please sign in to comment.