Skip to content

Commit 0f1c757

Browse files
Fill out some missing docs for bevy_assets (#17829)
# Objective `bevy_assets` has long been unapproachable for contributors and users. More and better documentation would help that. We're gradually moving towards globally denying missing docs (#3492)! However, writing all of the hundreds of missing doc strings in a single go will be miserable to review. ## Solution Remove the allow for missing docs temporarily, and then pick some easy missing doc warnings largely at random to tackle. Stop when the change set is starting to feel intimidating.
1 parent 02985c3 commit 0f1c757

File tree

14 files changed

+80
-10
lines changed

14 files changed

+80
-10
lines changed

crates/bevy_asset/src/assets.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl AssetIndexAllocator {
9595
/// [`AssetPath`]: crate::AssetPath
9696
#[derive(Asset, TypePath)]
9797
pub struct LoadedUntypedAsset {
98+
/// The handle to the loaded asset.
9899
#[dependency]
99100
pub handle: UntypedHandle,
100101
}
@@ -631,6 +632,7 @@ impl<'a, A: Asset> Iterator for AssetsMutIterator<'a, A> {
631632
}
632633
}
633634

635+
/// An error returned when an [`AssetIndex`] has an invalid generation.
634636
#[derive(Error, Debug)]
635637
#[error("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")]
636638
pub struct InvalidGenerationError {

crates/bevy_asset/src/event.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use core::fmt::Debug;
88
/// For an untyped equivalent, see [`UntypedAssetLoadFailedEvent`].
99
#[derive(Event, Clone, Debug)]
1010
pub struct AssetLoadFailedEvent<A: Asset> {
11+
/// The stable identifier of the asset that failed to load.
1112
pub id: AssetId<A>,
1213
/// The asset path that was attempted.
1314
pub path: AssetPath<'static>,
@@ -25,6 +26,7 @@ impl<A: Asset> AssetLoadFailedEvent<A> {
2526
/// An untyped version of [`AssetLoadFailedEvent`].
2627
#[derive(Event, Clone, Debug)]
2728
pub struct UntypedAssetLoadFailedEvent {
29+
/// The stable identifier of the asset that failed to load.
2830
pub id: UntypedAssetId,
2931
/// The asset path that was attempted.
3032
pub path: AssetPath<'static>,
@@ -43,6 +45,7 @@ impl<A: Asset> From<&AssetLoadFailedEvent<A>> for UntypedAssetLoadFailedEvent {
4345
}
4446

4547
/// Events that occur for a specific loaded [`Asset`], such as "value changed" events and "dependency" events.
48+
#[expect(missing_docs, reason = "Documenting the id fields is unhelpful.")]
4649
#[derive(Event, Reflect)]
4750
pub enum AssetEvent<A: Asset> {
4851
/// Emitted whenever an [`Asset`] is added.

crates/bevy_asset/src/folder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bevy_reflect::TypePath;
1010
/// [`AssetPath`]: crate::AssetPath
1111
#[derive(Asset, TypePath)]
1212
pub struct LoadedFolder {
13+
/// The handles of all assets stored in the folder.
1314
#[dependency]
1415
pub handles: Vec<UntypedHandle>,
1516
}

crates/bevy_asset/src/handle.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ impl<A: Asset> From<&mut Handle<A>> for UntypedAssetId {
291291
/// See [`Handle`] for more information.
292292
#[derive(Clone)]
293293
pub enum UntypedHandle {
294+
/// A strong handle, which will keep the referenced [`Asset`] alive until all strong handles are dropped.
294295
Strong(Arc<StrongHandle>),
296+
/// A weak handle, which does not keep the referenced [`Asset`] alive.
295297
Weak(UntypedAssetId),
296298
}
297299

@@ -535,7 +537,12 @@ pub enum UntypedAssetConversionError {
535537
#[error(
536538
"This UntypedHandle is for {found:?} and cannot be converted into a Handle<{expected:?}>"
537539
)]
538-
TypeIdMismatch { expected: TypeId, found: TypeId },
540+
TypeIdMismatch {
541+
/// The expected [`TypeId`] of the [`Handle`] being converted to.
542+
expected: TypeId,
543+
/// The [`TypeId`] of the [`UntypedHandle`] being converted from.
544+
found: TypeId,
545+
},
539546
}
540547

541548
#[cfg(test)]

crates/bevy_asset/src/id.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ pub enum AssetId<A: Asset> {
2626
///
2727
/// [`Assets`]: crate::Assets
2828
Index {
29+
/// The unstable, opaque index of the asset.
2930
index: AssetIndex,
31+
/// A marker to store the type information of the asset.
3032
#[reflect(ignore)]
3133
marker: PhantomData<fn() -> A>,
3234
},
3335
/// A stable-across-runs / const asset identifier. This will only be used if an asset is explicitly registered in [`Assets`]
3436
/// with one.
3537
///
3638
/// [`Assets`]: crate::Assets
37-
Uuid { uuid: Uuid },
39+
Uuid {
40+
/// The UUID provided during asset registration.
41+
uuid: Uuid,
42+
},
3843
}
3944

4045
impl<A: Asset> AssetId<A> {
@@ -165,12 +170,22 @@ pub enum UntypedAssetId {
165170
/// explicitly registered that way.
166171
///
167172
/// [`Assets`]: crate::Assets
168-
Index { type_id: TypeId, index: AssetIndex },
173+
Index {
174+
/// An identifier that records the underlying asset type.
175+
type_id: TypeId,
176+
/// The unstable, opaque index of the asset.
177+
index: AssetIndex,
178+
},
169179
/// A stable-across-runs / const asset identifier. This will only be used if an asset is explicitly registered in [`Assets`]
170180
/// with one.
171181
///
172182
/// [`Assets`]: crate::Assets
173-
Uuid { type_id: TypeId, uuid: Uuid },
183+
Uuid {
184+
/// An identifier that records the underlying asset type.
185+
type_id: TypeId,
186+
/// The UUID provided during asset registration.
187+
uuid: Uuid,
188+
},
174189
}
175190

176191
impl UntypedAssetId {
@@ -404,7 +419,12 @@ impl<A: Asset> TryFrom<UntypedAssetId> for AssetId<A> {
404419
pub enum UntypedAssetIdConversionError {
405420
/// Caused when trying to convert an [`UntypedAssetId`] into an [`AssetId`] of the wrong type.
406421
#[error("This UntypedAssetId is for {found:?} and cannot be converted into an AssetId<{expected:?}>")]
407-
TypeIdMismatch { expected: TypeId, found: TypeId },
422+
TypeIdMismatch {
423+
/// The [`TypeId`] of the asset that we are trying to convert to.
424+
expected: TypeId,
425+
/// The [`TypeId`] of the asset that we are trying to convert from.
426+
found: TypeId,
427+
},
408428
}
409429

410430
#[cfg(test)]

crates/bevy_asset/src/io/embedded/embedded_watcher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct EmbeddedWatcher {
2424
}
2525

2626
impl EmbeddedWatcher {
27+
/// Creates a new `EmbeddedWatcher` that watches for changes to the embedded assets in the given `dir`.
2728
pub fn new(
2829
dir: Dir,
2930
root_paths: Arc<RwLock<HashMap<Box<Path>, PathBuf>>>,

crates/bevy_asset/src/io/embedded/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use std::path::{Path, PathBuf};
1515
#[cfg(feature = "embedded_watcher")]
1616
use alloc::borrow::ToOwned;
1717

18+
/// The name of the `embedded` [`AssetSource`],
19+
/// as stored in the [`AssetSourceBuilders`] resource.
1820
pub const EMBEDDED: &str = "embedded";
1921

2022
/// A [`Resource`] that manages "rust source files" in a virtual in memory [`Dir`], which is intended
@@ -77,6 +79,7 @@ impl EmbeddedAssetRegistry {
7779
self.dir.remove_asset(full_path)
7880
}
7981

82+
/// Registers the [`EMBEDDED`] [`AssetSource`] with the given [`AssetSourceBuilders`].
8083
pub fn register_source(&self, sources: &mut AssetSourceBuilders) {
8184
let dir = self.dir.clone();
8285
let processed_dir = self.dir.clone();

crates/bevy_asset/src/io/file/file_watcher.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use std::path::{Path, PathBuf};
1818
use tracing::error;
1919

2020
/// An [`AssetWatcher`] that watches the filesystem for changes to asset files in a given root folder and emits [`AssetSourceEvent`]
21-
/// for each relevant change. This uses [`notify_debouncer_full`] to retrieve "debounced" filesystem events.
21+
/// for each relevant change.
22+
///
23+
/// This uses [`notify_debouncer_full`] to retrieve "debounced" filesystem events.
2224
/// "Debouncing" defines a time window to hold on to events and then removes duplicate events that fall into this window.
2325
/// This introduces a small delay in processing events, but it helps reduce event duplicates. A small delay is also necessary
2426
/// on some systems to avoid processing a change event before it has actually been applied.
@@ -27,6 +29,7 @@ pub struct FileWatcher {
2729
}
2830

2931
impl FileWatcher {
32+
/// Creates a new [`FileWatcher`] that watches for changes to the asset files in the given `path`.
3033
pub fn new(
3134
path: PathBuf,
3235
sender: Sender<AssetSourceEvent>,

crates/bevy_asset/src/io/file/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ impl FileAssetReader {
6565
}
6666
}
6767

68+
/// A writer for the local filesystem.
6869
pub struct FileAssetWriter {
6970
root_path: PathBuf,
7071
}
7172

7273
impl FileAssetWriter {
73-
/// Creates a new `FileAssetIo` at a path relative to the executable's directory, optionally
74+
/// Creates a new [`FileAssetWriter`] at a path relative to the executable's directory, optionally
7475
/// watching for changes.
75-
///
76-
/// See `get_base_path` below.
7776
pub fn new<P: AsRef<Path> + core::fmt::Debug>(path: P, create_root: bool) -> Self {
7877
let root_path = get_base_path().join(path.as_ref());
7978
if create_root {

crates/bevy_asset/src/io/source.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,34 @@ impl<'a> PartialEq for AssetSourceId<'a> {
132132
/// and whether or not the source is processed.
133133
#[derive(Default)]
134134
pub struct AssetSourceBuilder {
135+
/// The [`ErasedAssetReader`] to use on the unprocessed asset.
135136
pub reader: Option<Box<dyn FnMut() -> Box<dyn ErasedAssetReader> + Send + Sync>>,
137+
/// The [`ErasedAssetWriter`] to use on the unprocessed asset.
136138
pub writer: Option<Box<dyn FnMut(bool) -> Option<Box<dyn ErasedAssetWriter>> + Send + Sync>>,
139+
/// The [`AssetWatcher`] to use for unprocessed assets, if any.
137140
pub watcher: Option<
138141
Box<
139142
dyn FnMut(crossbeam_channel::Sender<AssetSourceEvent>) -> Option<Box<dyn AssetWatcher>>
140143
+ Send
141144
+ Sync,
142145
>,
143146
>,
147+
/// The [`ErasedAssetReader`] to use for processed assets.
144148
pub processed_reader: Option<Box<dyn FnMut() -> Box<dyn ErasedAssetReader> + Send + Sync>>,
149+
/// The [`ErasedAssetWriter`] to use for processed assets.
145150
pub processed_writer:
146151
Option<Box<dyn FnMut(bool) -> Option<Box<dyn ErasedAssetWriter>> + Send + Sync>>,
152+
/// The [`AssetWatcher`] to use for processed assets, if any.
147153
pub processed_watcher: Option<
148154
Box<
149155
dyn FnMut(crossbeam_channel::Sender<AssetSourceEvent>) -> Option<Box<dyn AssetWatcher>>
150156
+ Send
151157
+ Sync,
152158
>,
153159
>,
160+
/// The warning message to display when watching an unprocessed asset fails.
154161
pub watch_warning: Option<&'static str>,
162+
/// The warning message to display when watching a processed asset fails.
155163
pub processed_watch_warning: Option<&'static str>,
156164
}
157165

0 commit comments

Comments
 (0)