Cargo fmt with unstable features (#1903)

Fresh version of #1670 off the latest main.

Mostly fixing documentation wrapping.
This commit is contained in:
Alice Cecile 2021-04-21 23:19:34 +00:00
parent 30c6ca6166
commit e4e32598a9
20 changed files with 75 additions and 63 deletions

View file

@ -185,9 +185,9 @@ impl AppBuilder {
/// Adds a new [State] with the given `initial` value. /// Adds a new [State] with the given `initial` value.
/// This inserts a new `State<T>` resource and adds a new "driver" to [CoreStage::Update]. /// This inserts a new `State<T>` resource and adds a new "driver" to [CoreStage::Update].
/// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use your state in a /// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use
/// different stage, consider using [Self::add_state_to_stage] or manually adding [State::get_driver] to additional stages /// your state in a different stage, consider using [Self::add_state_to_stage] or manually
/// you need it in. /// adding [State::get_driver] to additional stages you need it in.
pub fn add_state<T>(&mut self, initial: T) -> &mut Self pub fn add_state<T>(&mut self, initial: T) -> &mut Self
where where
T: Component + Debug + Clone + Eq + Hash, T: Component + Debug + Clone + Eq + Hash,
@ -197,9 +197,9 @@ impl AppBuilder {
/// Adds a new [State] with the given `initial` value. /// Adds a new [State] with the given `initial` value.
/// This inserts a new `State<T>` resource and adds a new "driver" to the given stage. /// This inserts a new `State<T>` resource and adds a new "driver" to the given stage.
/// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use your state in /// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use
/// more than one stage, consider manually adding [State::get_driver] to the stages /// your state in more than one stage, consider manually adding [State::get_driver] to the
/// you need it in. /// stages you need it in.
pub fn add_state_to_stage<T>(&mut self, stage: impl StageLabel, initial: T) -> &mut Self pub fn add_state_to_stage<T>(&mut self, stage: impl StageLabel, initial: T) -> &mut Self
where where
T: Component + Debug + Clone + Eq + Hash, T: Component + Debug + Clone + Eq + Hash,

View file

@ -344,7 +344,8 @@ impl ComponentTicks {
} }
/// Manually sets the change tick. /// Manually sets the change tick.
/// Usually, this is done automatically via the [`DerefMut`](std::ops::DerefMut) implementation on [`Mut`](crate::world::Mut) or [`ResMut`](crate::system::ResMut) etc. /// Usually, this is done automatically via the [`DerefMut`](std::ops::DerefMut) implementation
/// on [`Mut`](crate::world::Mut) or [`ResMut`](crate::system::ResMut) etc.
/// ///
/// # Example /// # Example
/// ```rust,no_run /// ```rust,no_run

View file

@ -891,8 +891,7 @@ impl Stage for SystemStage {
mod tests { mod tests {
use crate::{ use crate::{
entity::Entity, entity::Entity,
query::ChangeTrackers, query::{ChangeTrackers, Changed},
query::Changed,
schedule::{ schedule::{
BoxedSystemLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion, BoxedSystemLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion,
RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaPiping, ShouldRun, RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaPiping, ShouldRun,

View file

@ -300,7 +300,8 @@ where
} }
/// Schedule a state change that replaces the full stack with the given state. /// Schedule a state change that replaces the full stack with the given state.
/// This will fail if there is a scheduled operation, or if the given `state` matches the current state /// This will fail if there is a scheduled operation, or if the given `state` matches the
/// current state
pub fn replace(&mut self, state: T) -> Result<(), StateError> { pub fn replace(&mut self, state: T) -> Result<(), StateError> {
if self.stack.last().unwrap() == &state { if self.stack.last().unwrap() == &state {
return Err(StateError::AlreadyInState); return Err(StateError::AlreadyInState);
@ -314,7 +315,8 @@ where
Ok(()) Ok(())
} }
/// Same as [Self::replace], but if there is already a next state, it will be overwritten instead of failing /// Same as [Self::replace], but if there is already a next state, it will be overwritten
/// instead of failing
pub fn overwrite_replace(&mut self, state: T) -> Result<(), StateError> { pub fn overwrite_replace(&mut self, state: T) -> Result<(), StateError> {
if self.stack.last().unwrap() == &state { if self.stack.last().unwrap() == &state {
return Err(StateError::AlreadyInState); return Err(StateError::AlreadyInState);

View file

@ -328,8 +328,8 @@ impl Table {
let available_space = self.capacity - self.len(); let available_space = self.capacity - self.len();
if available_space < amount { if available_space < amount {
let min_capacity = self.len() + amount; let min_capacity = self.len() + amount;
// normally we would check if min_capacity is 0 for the below calculation, but amount > available_space and // normally we would check if min_capacity is 0 for the below calculation, but amount >
// available_space > 0, so min_capacity > 1 // available_space and available_space > 0, so min_capacity > 1
let new_capacity = let new_capacity =
((min_capacity + self.grow_amount - 1) / self.grow_amount) * self.grow_amount; ((min_capacity + self.grow_amount - 1) / self.grow_amount) * self.grow_amount;
let reserve_amount = new_capacity - self.len(); let reserve_amount = new_capacity - self.len();

View file

@ -86,8 +86,8 @@ impl<'a> Commands<'a> {
/// Creates a new entity with the components contained in `bundle`. /// Creates a new entity with the components contained in `bundle`.
/// ///
/// This returns an [`EntityCommands`] builder, which enables inserting more components and bundles /// This returns an [`EntityCommands`] builder, which enables inserting more components and
/// using a "builder pattern". /// bundles using a "builder pattern".
/// ///
/// Note that `bundle` is a [`Bundle`], which is a collection of components. [`Bundle`] is /// Note that `bundle` is a [`Bundle`], which is a collection of components. [`Bundle`] is
/// automatically implemented for tuples of components. You can also create your own bundle /// automatically implemented for tuples of components. You can also create your own bundle
@ -212,9 +212,9 @@ impl<'a, 'b> EntityCommands<'a, 'b> {
/// # Warning /// # Warning
/// ///
/// It's possible to call this with a bundle, but this is likely not intended and /// It's possible to call this with a bundle, but this is likely not intended and
/// [`Self::insert_bundle`] should be used instead. If `with` is called with a bundle, the bundle /// [`Self::insert_bundle`] should be used instead. If `with` is called with a bundle, the
/// itself will be added as a component instead of the bundles' inner components each being /// bundle itself will be added as a component instead of the bundles' inner components each
/// added. /// being added.
/// ///
/// # Example /// # Example
/// ///

View file

@ -51,7 +51,8 @@ impl SystemState {
/// Conversion trait to turn something into a [`System`]. /// Conversion trait to turn something into a [`System`].
/// ///
/// Use this to get a system from a function. Also note that every system implements this trait as well. /// Use this to get a system from a function. Also note that every system implements this trait as
/// well.
/// ///
/// # Examples /// # Examples
/// ///
@ -106,9 +107,9 @@ pub struct InputMarker;
/// The [`System`] counter part of an ordinary function. /// The [`System`] counter part of an ordinary function.
/// ///
/// You get this by calling [`IntoSystem::system`] on a function that only accepts [`SystemParam`]s. /// You get this by calling [`IntoSystem::system`] on a function that only accepts
/// The output of the system becomes the functions return type, while the input becomes the functions /// [`SystemParam`]s. The output of the system becomes the functions return type, while the input
/// [`In`] tagged parameter or `()` if no such paramater exists. /// becomes the functions [`In`] tagged parameter or `()` if no such paramater exists.
pub struct FunctionSystem<In, Out, Param, Marker, F> pub struct FunctionSystem<In, Out, Param, Marker, F>
where where
Param: SystemParam, Param: SystemParam,

View file

@ -126,7 +126,8 @@ where
/// Runs `f` on each query result in parallel using the given task pool. /// Runs `f` on each query result in parallel using the given task pool.
/// ///
/// This can only be called for read-only queries, see [`Self::par_for_each_mut`] for write-queries. /// This can only be called for read-only queries, see [`Self::par_for_each_mut`] for
/// write-queries.
#[inline] #[inline]
pub fn par_for_each( pub fn par_for_each(
&self, &self,
@ -270,7 +271,8 @@ where
} }
/// Gets a mutable reference to the [`Entity`]'s [`Component`] of the given type. This will fail /// Gets a mutable reference to the [`Entity`]'s [`Component`] of the given type. This will fail
/// if the entity does not have the given component type or the component does not match the query. /// if the entity does not have the given component type or the component does not match the
/// query.
/// ///
/// # Safety /// # Safety
/// ///
@ -352,7 +354,8 @@ where
} }
} }
/// Gets the query result if it is only a single result, otherwise returns a [`QuerySingleError`]. /// Gets the query result if it is only a single result, otherwise returns a
/// [`QuerySingleError`].
pub fn single_mut(&mut self) -> Result<<Q::Fetch as Fetch<'_>>::Item, QuerySingleError> { pub fn single_mut(&mut self) -> Result<<Q::Fetch as Fetch<'_>>::Item, QuerySingleError> {
let mut query = self.iter_mut(); let mut query = self.iter_mut();
let first = query.next(); let first = query.next();
@ -381,8 +384,8 @@ pub enum QueryComponentError {
NoSuchEntity, NoSuchEntity,
} }
/// An error that occurs when evaluating a [`Query`] as a single expected resulted via [`Query::single`] /// An error that occurs when evaluating a [`Query`] as a single expected resulted via
/// or [`Query::single_mut`]. /// [`Query::single`] or [`Query::single_mut`].
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum QuerySingleError { pub enum QuerySingleError {
#[error("No entities fit the query {0}")] #[error("No entities fit the query {0}")]

View file

@ -31,7 +31,8 @@ impl SystemId {
/// It's possible to specify explicit execution order between specific systems, /// It's possible to specify explicit execution order between specific systems,
/// see [SystemDescriptor](crate::schedule::SystemDescriptor). /// see [SystemDescriptor](crate::schedule::SystemDescriptor).
pub trait System: Send + Sync + 'static { pub trait System: Send + Sync + 'static {
/// The system's input. See [`In`](crate::system::In) for [`FunctionSystem`](crate::system::FunctionSystem)s. /// The system's input. See [`In`](crate::system::In) for
/// [`FunctionSystem`](crate::system::FunctionSystem)s.
type In; type In;
/// The system's output. /// The system's output.
type Out; type Out;

View file

@ -74,8 +74,8 @@ where
self.just_pressed.contains(&input) self.just_pressed.contains(&input)
} }
/// Clear the "just pressed" state of `input`. Future calls to [`Input::just_pressed`] for the given /// Clear the "just pressed" state of `input`. Future calls to [`Input::just_pressed`] for the
/// input will return false until a new press event occurs. /// given input will return false until a new press event occurs.
/// Returns true if `input` is currently "just pressed" /// Returns true if `input` is currently "just pressed"
pub fn clear_just_pressed(&mut self, input: T) -> bool { pub fn clear_just_pressed(&mut self, input: T) -> bool {
self.just_pressed.remove(&input) self.just_pressed.remove(&input)
@ -86,8 +86,8 @@ where
self.just_released.contains(&input) self.just_released.contains(&input)
} }
/// Clear the "just released" state of `input`. Future calls to [`Input::just_released`] for the given /// Clear the "just released" state of `input`. Future calls to [`Input::just_released`] for the
/// input will return false until a new release event occurs. /// given input will return false until a new release event occurs.
/// Returns true if `input` is currently "just released" /// Returns true if `input` is currently "just released"
pub fn clear_just_released(&mut self, input: T) -> bool { pub fn clear_just_released(&mut self, input: T) -> bool {
self.just_released.remove(&input) self.just_released.remove(&input)

View file

@ -7,20 +7,20 @@ use bevy_render::{color::Color, renderer::RenderResources, shader::ShaderDefs, t
#[derive(Debug, RenderResources, ShaderDefs, TypeUuid)] #[derive(Debug, RenderResources, ShaderDefs, TypeUuid)]
#[uuid = "dace545e-4bc6-4595-a79d-c224fc694975"] #[uuid = "dace545e-4bc6-4595-a79d-c224fc694975"]
pub struct StandardMaterial { pub struct StandardMaterial {
/// Doubles as diffuse albedo for non-metallic, specular for metallic and a mix for everything in between /// Doubles as diffuse albedo for non-metallic, specular for metallic and a mix for everything
/// If used together with a base_color_texture, this is factored into the final base color /// in between If used together with a base_color_texture, this is factored into the final
/// as `base_color * base_color_texture_value` /// base color as `base_color * base_color_texture_value`
pub base_color: Color, pub base_color: Color,
#[shader_def] #[shader_def]
pub base_color_texture: Option<Handle<Texture>>, pub base_color_texture: Option<Handle<Texture>>,
/// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader /// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader
/// Defaults to minimum of 0.089 /// Defaults to minimum of 0.089
/// If used together with a roughness/metallic texture, this is factored into the final base color /// If used together with a roughness/metallic texture, this is factored into the final base
/// as `roughness * roughness_texture_value` /// color as `roughness * roughness_texture_value`
pub roughness: f32, pub roughness: f32,
/// From [0.0, 1.0], dielectric to pure metallic /// From [0.0, 1.0], dielectric to pure metallic
/// If used together with a roughness/metallic texture, this is factored into the final base color /// If used together with a roughness/metallic texture, this is factored into the final base
/// as `metallic * metallic_texture_value` /// color as `metallic * metallic_texture_value`
pub metallic: f32, pub metallic: f32,
/// Specular intensity for non-metals on a linear scale of [0.0, 1.0] /// Specular intensity for non-metals on a linear scale of [0.0, 1.0]
/// defaults to 0.5 which is mapped to 4% reflectance in the shader /// defaults to 0.5 which is mapped to 4% reflectance in the shader
@ -51,8 +51,9 @@ impl Default for StandardMaterial {
base_color_texture: None, base_color_texture: None,
// This is the minimum the roughness is clamped to in shader code // This is the minimum the roughness is clamped to in shader code
// See https://google.github.io/filament/Filament.html#materialsystem/parameterization/ // See https://google.github.io/filament/Filament.html#materialsystem/parameterization/
// It's the minimum floating point value that won't be rounded down to 0 in the calculations used. // It's the minimum floating point value that won't be rounded down to 0 in the
// Although technically for 32-bit floats, 0.045 could be used. // calculations used. Although technically for 32-bit floats, 0.045 could be
// used.
roughness: 0.089, roughness: 0.089,
// Few materials are purely dielectric or metallic // Few materials are purely dielectric or metallic
// This is just a default for mostly-dielectric // This is just a default for mostly-dielectric

View file

@ -24,8 +24,9 @@ pub enum ReflectMut<'a> {
/// A reflected rust type. /// A reflected rust type.
/// ///
/// # Safety /// # Safety
/// Implementors _must_ ensure that [Reflect::any] and [Reflect::any_mut] both return the `self` value passed in /// Implementors _must_ ensure that [Reflect::any] and [Reflect::any_mut] both return the `self`
/// If this is not done, [Reflect::downcast] will be UB (and also just logically broken). /// value passed in If this is not done, [Reflect::downcast] will be UB (and also just logically
/// broken).
pub unsafe trait Reflect: Any + Send + Sync { pub unsafe trait Reflect: Any + Send + Sync {
fn type_name(&self) -> &str; fn type_name(&self) -> &str;
fn any(&self) -> &dyn Any; fn any(&self) -> &dyn Any;

View file

@ -25,7 +25,8 @@ pub enum Color {
/// Alpha component. [0.0, 1.0] /// Alpha component. [0.0, 1.0]
alpha: f32, alpha: f32,
}, },
/// RGBA color in the Linear sRGB colorspace (often colloquially referred to as "linear", "RGB", or "linear RGB"). /// RGBA color in the Linear sRGB colorspace (often colloquially referred to as "linear",
/// "RGB", or "linear RGB").
RgbaLinear { RgbaLinear {
/// Red component. [0.0, 1.0] /// Red component. [0.0, 1.0]
red: f32, red: f32,

View file

@ -222,8 +222,8 @@ impl From<&Indices> for IndexFormat {
#[uuid = "8ecbac0f-f545-4473-ad43-e1f4243af51e"] #[uuid = "8ecbac0f-f545-4473-ad43-e1f4243af51e"]
pub struct Mesh { pub struct Mesh {
primitive_topology: PrimitiveTopology, primitive_topology: PrimitiveTopology,
/// `std::collections::BTreeMap` with all defined vertex attributes (Positions, Normals, ...) for this /// `std::collections::BTreeMap` with all defined vertex attributes (Positions, Normals, ...)
/// mesh. Attribute name maps to attribute values. /// for this mesh. Attribute name maps to attribute values.
/// Uses a BTreeMap because, unlike HashMap, it has a defined iteration order, /// Uses a BTreeMap because, unlike HashMap, it has a defined iteration order,
/// which allows easy stable VertexBuffers (i.e. same buffer order) /// which allows easy stable VertexBuffers (i.e. same buffer order)
attributes: BTreeMap<Cow<'static, str>, VertexAttributeValues>, attributes: BTreeMap<Cow<'static, str>, VertexAttributeValues>,

View file

@ -167,7 +167,8 @@ where
} }
for render_command in draw.render_commands.iter() { for render_command in draw.render_commands.iter() {
commands.push(render_command.clone()); commands.push(render_command.clone());
// whenever a new pipeline is set, ensure the relevant camera bind groups are set // whenever a new pipeline is set, ensure the relevant camera bind groups
// are set
if let RenderCommand::SetPipeline { pipeline } = render_command { if let RenderCommand::SetPipeline { pipeline } = render_command {
let bind_groups = pipeline_camera_commands let bind_groups = pipeline_camera_commands
.entry(pipeline.clone_weak()) .entry(pipeline.clone_weak())

View file

@ -53,9 +53,9 @@ impl Default for Text2dBundle {
} }
} }
/// System for drawing text in a 2D scene via a 2D `OrthographicCameraBundle`. Included in the default /// System for drawing text in a 2D scene via a 2D `OrthographicCameraBundle`. Included in the
/// `TextPlugin`. Position is determined by the `Transform`'s translation, though scale and rotation /// default `TextPlugin`. Position is determined by the `Transform`'s translation, though scale and
/// are ignored. /// rotation are ignored.
pub fn draw_text2d_system( pub fn draw_text2d_system(
mut context: DrawContext, mut context: DrawContext,
msaa: Res<Msaa>, msaa: Res<Msaa>,

View file

@ -169,7 +169,8 @@ fn setup(
let mut first_pass_camera = PerspectiveCameraBundle { let mut first_pass_camera = PerspectiveCameraBundle {
camera: Camera { camera: Camera {
name: Some(FIRST_PASS_CAMERA.to_string()), name: Some(FIRST_PASS_CAMERA.to_string()),
window: WindowId::new(), // otherwise it will use main window size / aspect for calculation of projection matrix window: WindowId::new(), /* otherwise it will use main window size / aspect for
* calculation of projection matrix */
..Default::default() ..Default::default()
}, },
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0)) transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))

View file

@ -84,7 +84,8 @@ fn setup(
fragment: Some(shaders.add(Shader::from_glsl(ShaderStage::Fragment, FRAGMENT_SHADER))), fragment: Some(shaders.add(Shader::from_glsl(ShaderStage::Fragment, FRAGMENT_SHADER))),
})); }));
// Add a `RenderResourcesNode` to our `RenderGraph`. This will bind `TimeComponent` to our shader. // Add a `RenderResourcesNode` to our `RenderGraph`. This will bind `TimeComponent` to our
// shader.
render_graph.add_system_node( render_graph.add_system_node(
"time_uniform", "time_uniform",
RenderResourcesNode::<TimeUniform>::new(true), RenderResourcesNode::<TimeUniform>::new(true),
@ -115,9 +116,9 @@ fn setup(
}); });
} }
/// In this system we query for the `TimeComponent` and global `Time` resource, and set `time.seconds_since_startup()` /// In this system we query for the `TimeComponent` and global `Time` resource, and set
/// as the `value` of the `TimeComponent`. This value will be accessed by the fragment shader and used /// `time.seconds_since_startup()` as the `value` of the `TimeComponent`. This value will be
/// to animate the shader. /// accessed by the fragment shader and used to animate the shader.
fn animate_shader(time: Res<Time>, mut query: Query<&mut TimeUniform>) { fn animate_shader(time: Res<Time>, mut query: Query<&mut TimeUniform>) {
let mut time_uniform = query.single_mut().unwrap(); let mut time_uniform = query.single_mut().unwrap();
time_uniform.value = time.seconds_since_startup() as f32; time_uniform.value = time.seconds_since_startup() as f32;

View file

@ -5,7 +5,6 @@ newline_style = "Unix"
# Once these features have stabilized, they should be added to the always-enabled options above. # Once these features have stabilized, they should be added to the always-enabled options above.
# unstable_features = true # unstable_features = true
# imports_granularity = "Crate" # imports_granularity = "Crate"
#reorder_impl_items = true
# wrap_comments = true # wrap_comments = true
# comment_width = 100 # comment_width = 100
# normalize_comments = true # normalize_comments = true