Skip to content

Commit 5c82d76

Browse files
Assorted missing docs
1 parent bd200de commit 5c82d76

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
}
@@ -629,6 +630,7 @@ impl<'a, A: Asset> Iterator for AssetsMutIterator<'a, A> {
629630
}
630631
}
631632

633+
/// An error returned when an [`AssetIndex`] has an invalid generation.
632634
#[derive(Error, Debug)]
633635
#[error("AssetIndex {index:?} has an invalid generation. The current generation is: '{current_generation}'.")]
634636
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
@@ -8,6 +8,7 @@ use bevy_reflect::TypePath;
88
/// [`AssetPath`]: crate::AssetPath
99
#[derive(Asset, TypePath)]
1010
pub struct LoadedFolder {
11+
/// The handles of all assets stored in the folder.
1112
#[dependency]
1213
pub handles: Vec<UntypedHandle>,
1314
}

crates/bevy_asset/src/handle.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ impl<A: Asset> From<&mut Handle<A>> for UntypedAssetId {
284284
/// See [`Handle`] for more information.
285285
#[derive(Clone)]
286286
pub enum UntypedHandle {
287+
/// A strong handle, which will keep the referenced [`Asset`] alive until all strong handles are dropped.
287288
Strong(Arc<StrongHandle>),
289+
/// A weak handle, which does not keep the referenced [`Asset`] alive.
288290
Weak(UntypedAssetId),
289291
}
290292

@@ -528,7 +530,12 @@ pub enum UntypedAssetConversionError {
528530
#[error(
529531
"This UntypedHandle is for {found:?} and cannot be converted into a Handle<{expected:?}>"
530532
)]
531-
TypeIdMismatch { expected: TypeId, found: TypeId },
533+
TypeIdMismatch {
534+
/// The expected [`TypeId`] of the [`Handle`] being converted to.
535+
expected: TypeId,
536+
/// The [`TypeId`] of the [`UntypedHandle`] being converted from.
537+
found: TypeId,
538+
},
532539
}
533540

534541
#[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

crates/bevy_asset/src/processor/log.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ pub struct ProcessorTransactionLog {
3232
/// An error that occurs when reading from the [`ProcessorTransactionLog`] fails.
3333
#[derive(Error, Debug)]
3434
pub enum ReadLogError {
35+
/// An invalid log line was encountered, consisting of the contained string.
3536
#[error("Encountered an invalid log line: '{0}'")]
3637
InvalidLine(String),
38+
/// A file-system-based error occurred while reading the log file.
3739
#[error("Failed to read log file: {0}")]
3840
Io(#[from] futures_io::Error),
3941
}
@@ -51,21 +53,27 @@ pub struct WriteLogError {
5153
/// An error that occurs when validating the [`ProcessorTransactionLog`] fails.
5254
#[derive(Error, Debug)]
5355
pub enum ValidateLogError {
56+
/// An error that could not be recovered from. All assets will be reprocessed.
5457
#[error("Encountered an unrecoverable error. All assets will be reprocessed.")]
5558
UnrecoverableError,
59+
/// A [`ReadLogError`].
5660
#[error(transparent)]
5761
ReadLogError(#[from] ReadLogError),
62+
/// Duplicated process asset transactions occurred.
5863
#[error("Encountered a duplicate process asset transaction: {0:?}")]
5964
EntryErrors(Vec<LogEntryError>),
6065
}
6166

6267
/// An error that occurs when validating individual [`ProcessorTransactionLog`] entries.
6368
#[derive(Error, Debug)]
6469
pub enum LogEntryError {
70+
/// A duplicate process asset transaction occurred for the given asset path.
6571
#[error("Encountered a duplicate process asset transaction: {0}")]
6672
DuplicateTransaction(AssetPath<'static>),
73+
/// A transaction was ended that never started for the given asset path.
6774
#[error("A transaction was ended that never started {0}")]
6875
EndedMissingTransaction(AssetPath<'static>),
76+
/// An asset started processing but never finished at the given asset path.
6977
#[error("An asset started processing but never finished: {0}")]
7078
UnfinishedTransaction(AssetPath<'static>),
7179
}

crates/bevy_asset/src/render_asset.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ bitflags::bitflags! {
2929
#[reflect(opaque)]
3030
#[reflect(Serialize, Deserialize, Hash, PartialEq, Debug)]
3131
pub struct RenderAssetUsages: u8 {
32+
/// The bit flag for the main world.
3233
const MAIN_WORLD = 1 << 0;
34+
/// The bit flag for the render world.
3335
const RENDER_WORLD = 1 << 1;
3436
}
3537
}

crates/bevy_asset/src/server/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,10 @@ impl RecursiveDependencyLoadState {
17371737

17381738
/// An error that occurs during an [`Asset`] load.
17391739
#[derive(Error, Debug, Clone)]
1740+
#[expect(
1741+
missing_docs,
1742+
reason = "Adding docs to the variants would not add information beyond the error message and the names"
1743+
)]
17401744
pub enum AssetLoadError {
17411745
#[error("Requested handle of type {requested:?} for asset '{path}' does not match actual asset type '{actual_asset_name}', which used loader '{loader_name}'")]
17421746
RequestedHandleTypeMismatch {
@@ -1798,6 +1802,7 @@ pub enum AssetLoadError {
17981802
},
17991803
}
18001804

1805+
/// An error that can occur during asset loading.
18011806
#[derive(Error, Debug, Clone)]
18021807
#[error("Failed to load asset '{path}' with asset loader '{loader_name}': {error}")]
18031808
pub struct AssetLoaderError {
@@ -1807,11 +1812,13 @@ pub struct AssetLoaderError {
18071812
}
18081813

18091814
impl AssetLoaderError {
1815+
/// The path of the asset that failed to load.
18101816
pub fn path(&self) -> &AssetPath<'static> {
18111817
&self.path
18121818
}
18131819
}
18141820

1821+
/// An error that occurs while resolving an asset added by `add_async`.
18151822
#[derive(Error, Debug, Clone)]
18161823
#[error("An error occurred while resolving an asset added by `add_async`: {error}")]
18171824
pub struct AddAsyncError {
@@ -1829,13 +1836,15 @@ pub struct MissingAssetLoaderForExtensionError {
18291836
#[derive(Error, Debug, Clone, PartialEq, Eq)]
18301837
#[error("no `AssetLoader` found with the name '{type_name}'")]
18311838
pub struct MissingAssetLoaderForTypeNameError {
1832-
type_name: String,
1839+
/// The type name that was not found.
1840+
pub type_name: String,
18331841
}
18341842

18351843
/// An error that occurs when an [`AssetLoader`] is not registered for a given [`Asset`] [`TypeId`].
18361844
#[derive(Error, Debug, Clone, PartialEq, Eq)]
18371845
#[error("no `AssetLoader` found with the ID '{type_id:?}'")]
18381846
pub struct MissingAssetLoaderForTypeIdError {
1847+
/// The type ID that was not found.
18391848
pub type_id: TypeId,
18401849
}
18411850

@@ -1866,10 +1875,13 @@ const UNTYPED_SOURCE_SUFFIX: &str = "--untyped";
18661875
/// An error when attempting to wait asynchronously for an [`Asset`] to load.
18671876
#[derive(Error, Debug, Clone)]
18681877
pub enum WaitForAssetError {
1878+
/// The asset is not being loaded; waiting for it is meaningless.
18691879
#[error("tried to wait for an asset that is not being loaded")]
18701880
NotLoaded,
1881+
/// The asset failed to load.
18711882
#[error(transparent)]
18721883
Failed(Arc<AssetLoadError>),
1884+
/// A dependency of the asset failed to load.
18731885
#[error(transparent)]
18741886
DependencyFailed(Arc<AssetLoadError>),
18751887
}

crates/bevy_asset/src/transformer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ pub struct IdentityAssetTransformer<A: Asset> {
153153
}
154154

155155
impl<A: Asset> IdentityAssetTransformer<A> {
156+
/// Creates a new [`IdentityAssetTransformer`] with the correct internal [`PhantomData`] field.
156157
pub const fn new() -> Self {
157158
Self {
158159
_phantom: PhantomData,

0 commit comments

Comments
 (0)