Skip to content

Commit c8f2933

Browse files
committed
Rename write_single and write_multiple to write_full and write_partial respectively.
1 parent 9ccaaf9 commit c8f2933

File tree

6 files changed

+76
-81
lines changed

6 files changed

+76
-81
lines changed

crates/bevy_asset/src/processor/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ impl AssetProcessor {
777777
}
778778
{
779779
// If this directory has a meta file, then it is likely a processed asset using
780-
// `ProcessContext::write_multiple`, so count the whole thing as an asset path.
780+
// `ProcessContext::write_partial`, so count the whole thing as an asset path.
781781
paths.push(path);
782782
return Ok(true);
783783
}
@@ -1170,7 +1170,7 @@ impl AssetProcessor {
11701170
if let Some(processor) = processor {
11711171
let mut started_writes = 0;
11721172
let mut finished_writes = AtomicU32::new(0);
1173-
let mut single_meta = None;
1173+
let mut full_meta = None;
11741174
processor
11751175
.process(
11761176
&mut ProcessContext::new(
@@ -1184,7 +1184,7 @@ impl AssetProcessor {
11841184
processed_writer,
11851185
&mut started_writes,
11861186
&mut finished_writes,
1187-
&mut single_meta,
1187+
&mut full_meta,
11881188
asset_path,
11891189
),
11901190
)
@@ -1203,7 +1203,7 @@ impl AssetProcessor {
12031203
.iter()
12041204
.map(|i| i.full_hash),
12051205
);
1206-
let mut processed_meta = single_meta
1206+
let mut processed_meta = full_meta
12071207
.unwrap_or_else(|| Box::new(AssetMeta::<(), ()>::new(AssetAction::Decomposed)));
12081208

12091209
new_processed_info.full_hash = full_hash;

crates/bevy_asset/src/processor/process.rs

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ where
206206

207207
let saver = &self.saver;
208208
let saver_settings = &settings.saver_settings;
209-
let mut writer = writer_context.write_single().await?;
209+
let mut writer = writer_context.write_full().await?;
210210

211211
let output_settings = saver
212212
.save(&mut *writer, saved_asset, saver_settings)
@@ -347,18 +347,18 @@ pub struct WriterContext<'a> {
347347
/// The underlying writer of all writes for the [`Process`].
348348
writer: &'a dyn ErasedAssetWriter,
349349
/// The context for initializing a write.
350-
// We use a Mutex to avoid requiring a mutable borrow for `write_multiple`. See `write_multiple`
350+
// We use a Mutex to avoid requiring a mutable borrow for `write_partial`. See `write_partial`
351351
// for more details.
352352
init_context: Mutex<WriteInitContext<'a>>,
353353
/// The number of writes that have been fully finished.
354354
///
355355
/// Note we use an `AtomicU32` instead of a u32 so that writes (and therefore finish's) don't
356-
/// need to be synchronous. We use a mutable borrow so that single-writes can just update the
356+
/// need to be synchronous. We use a mutable borrow so that full-writes can just update the
357357
/// value without atomics.
358358
finished_writes: &'a mut AtomicU32,
359359
/// The meta object to write when writing a single file. Must be set to [`Some`] when writing a
360-
/// single file.
361-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
360+
/// "full" file.
361+
full_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
362362
/// The path of the asset being processed.
363363
path: &'a AssetPath<'static>,
364364
}
@@ -367,7 +367,7 @@ pub struct WriterContext<'a> {
367367
struct WriteInitContext<'a> {
368368
/// The number of writes that have been started.
369369
started_writes: &'a mut u32,
370-
/// The set of currently started `write_multiple` instances.
370+
/// The set of currently started [`WriterContext::write_partial`] instances.
371371
///
372372
/// This protects us from starting writes for the same path multiple times.
373373
started_paths: HashSet<PathBuf>,
@@ -378,7 +378,7 @@ impl<'a> WriterContext<'a> {
378378
writer: &'a dyn ErasedAssetWriter,
379379
started_writes: &'a mut u32,
380380
finished_writes: &'a mut AtomicU32,
381-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
381+
full_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
382382
path: &'a AssetPath<'static>,
383383
) -> Self {
384384
Self {
@@ -388,23 +388,23 @@ impl<'a> WriterContext<'a> {
388388
started_paths: HashSet::new(),
389389
}),
390390
finished_writes,
391-
single_meta,
391+
full_meta,
392392
path,
393393
}
394394
}
395395

396396
/// Start writing a single output file, which can be loaded with the `load_settings`.
397397
///
398-
/// Returns an error if you have previously called [`Self::write_multiple`].
399-
pub async fn write_single(self) -> Result<SingleWriter<'a>, ProcessError> {
398+
/// Returns an error if you have previously called [`Self::write_partial`].
399+
pub async fn write_full(self) -> Result<FullWriter<'a>, ProcessError> {
400400
let started_writes = self
401401
.init_context
402402
.into_inner()
403403
.unwrap_or_else(PoisonError::into_inner)
404404
.started_writes;
405405
if *started_writes != 0 {
406406
return Err(ProcessError::InvalidProcessOutput(
407-
InvalidProcessOutput::SingleFileAfterMultipleFile,
407+
InvalidProcessOutput::FullFileAfterPartialFile,
408408
));
409409
}
410410
*started_writes = 1;
@@ -415,21 +415,19 @@ impl<'a> WriterContext<'a> {
415415
err,
416416
}
417417
})?;
418-
Ok(SingleWriter {
418+
Ok(FullWriter {
419419
writer,
420420
finished_writes: self.finished_writes.get_mut(),
421421
path: self.path,
422-
single_meta: self.single_meta,
422+
meta: self.full_meta,
423423
})
424424
}
425425

426-
/// Start writing one of multiple output file, which can be loaded with the `load_settings`.
427-
///
428-
/// Returns an error if you have previously started writing a single file.
426+
/// Start writing one of multiple output files, which can be loaded with the `load_settings`.
429427
// Note: It would be nice to take this by a mutable reference instead. However, doing so would
430428
// mean that the returned value would be tied to a "mutable reference lifetime", meaning we
431-
// could not use more than one `MultipleWriter` instance concurrently.
432-
pub async fn write_multiple(&self, file: &Path) -> Result<MultipleWriter<'_>, ProcessError> {
429+
// could not use more than one `PartialWriter` instance concurrently.
430+
pub async fn write_partial(&self, file: &Path) -> Result<PartialWriter<'_>, ProcessError> {
433431
// Do all the validation in a scope so we don't hold the init_context for too long.
434432
{
435433
let mut init_context = self
@@ -439,7 +437,7 @@ impl<'a> WriterContext<'a> {
439437
// Check whether this path is valid first so that we don't mark the write as started
440438
// when it hasn't.
441439
if !init_context.started_paths.insert(file.to_path_buf()) {
442-
return Err(InvalidProcessOutput::RepeatedMultipleWriteToSamePath(
440+
return Err(InvalidProcessOutput::RepeatedPartialWriteToSamePath(
443441
file.to_path_buf(),
444442
)
445443
.into());
@@ -463,7 +461,7 @@ impl<'a> WriterContext<'a> {
463461
path: path.clone_owned(),
464462
err,
465463
})?;
466-
Ok(MultipleWriter {
464+
Ok(PartialWriter {
467465
meta_writer: self.writer,
468466
writer,
469467
finished_writes: &*self.finished_writes,
@@ -476,32 +474,34 @@ impl<'a> WriterContext<'a> {
476474
#[derive(Error, Debug)]
477475
pub enum InvalidProcessOutput {
478476
/// The processor didn't start a write at all.
479-
#[error("The processor never started writing a file (never called `write_single` or `write_multiple`)")]
477+
#[error(
478+
"The processor never started writing a file (never called `write_full` or `write_partial`)"
479+
)]
480480
NoWriter,
481481
/// The processor started a write but never finished it.
482482
#[error("The processor started writing a file, but never called `finish`")]
483483
UnfinishedWriter,
484-
/// The processor started at least one multiple write, then continued with a single write.
485-
#[error("The processor called `write_single` after already calling `write_multiple`")]
486-
SingleFileAfterMultipleFile,
487-
/// The processor started a multiple write with the same path multiple times.
488-
#[error("The processor called `write_multiple` more than once with the same path")]
489-
RepeatedMultipleWriteToSamePath(PathBuf),
484+
/// The processor started at least one partial write, then continued with a full write.
485+
#[error("The processor called `write_full` after already calling `write_partial`")]
486+
FullFileAfterPartialFile,
487+
/// The processor started a partial write with the same path multiple times.
488+
#[error("The processor called `write_partial` more than once with the same path")]
489+
RepeatedPartialWriteToSamePath(PathBuf),
490490
}
491491

492492
/// The writer for a [`Process`] writing a single file (at the same path as the unprocessed asset).
493-
pub struct SingleWriter<'a> {
493+
pub struct FullWriter<'a> {
494494
/// The writer to write to.
495495
writer: Box<Writer>,
496496
/// The counter for finished writes that will be incremented when the write completes.
497497
finished_writes: &'a mut u32,
498498
/// The meta object that will be assigned on [`Self::finish`].
499-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
499+
meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
500500
/// The path of the asset being written.
501501
path: &'a AssetPath<'static>,
502502
}
503503

504-
impl SingleWriter<'_> {
504+
impl FullWriter<'_> {
505505
/// Finishes a write and indicates that the written asset should be loaded with the provided
506506
/// loader and the provided settings for that loader.
507507
///
@@ -525,8 +525,8 @@ impl SingleWriter<'_> {
525525

526526
// This should always be none, since we consumed the WriterContext, and we consume the
527527
// only borrow here.
528-
assert!(self.single_meta.is_none());
529-
*self.single_meta = Some(Box::new(output_meta));
528+
assert!(self.meta.is_none());
529+
*self.meta = Some(Box::new(output_meta));
530530

531531
// Make sure to increment finished writes at the very end, so that we only count it, once
532532
// the future is finished anyway.
@@ -535,8 +535,9 @@ impl SingleWriter<'_> {
535535
}
536536
}
537537

538-
/// A writer for a [`Process`] writing multiple files (as children of the unprocessed asset path).
539-
pub struct MultipleWriter<'a> {
538+
/// A writer for a [`Process`] writing multiple partial files (as children of the unprocessed asset
539+
/// path).
540+
pub struct PartialWriter<'a> {
540541
/// The writer to use when writing the meta file for this file.
541542
meta_writer: &'a dyn ErasedAssetWriter,
542543
/// The writer to write to.
@@ -549,7 +550,7 @@ pub struct MultipleWriter<'a> {
549550
path: AssetPath<'static>,
550551
}
551552

552-
impl MultipleWriter<'_> {
553+
impl PartialWriter<'_> {
553554
/// Finishes a write and indicates that the written asset should be loaded with the provided
554555
/// loader and the provided settings for that loader.
555556
///
@@ -592,29 +593,29 @@ impl MultipleWriter<'_> {
592593
}
593594
}
594595

595-
impl Deref for SingleWriter<'_> {
596+
impl Deref for FullWriter<'_> {
596597
type Target = Writer;
597598

598599
fn deref(&self) -> &Self::Target {
599600
self.writer.as_ref()
600601
}
601602
}
602603

603-
impl DerefMut for SingleWriter<'_> {
604+
impl DerefMut for FullWriter<'_> {
604605
fn deref_mut(&mut self) -> &mut Self::Target {
605606
self.writer.as_mut()
606607
}
607608
}
608609

609-
impl Deref for MultipleWriter<'_> {
610+
impl Deref for PartialWriter<'_> {
610611
type Target = Writer;
611612

612613
fn deref(&self) -> &Self::Target {
613614
self.writer.as_ref()
614615
}
615616
}
616617

617-
impl DerefMut for MultipleWriter<'_> {
618+
impl DerefMut for PartialWriter<'_> {
618619
fn deref_mut(&mut self) -> &mut Self::Target {
619620
self.writer.as_mut()
620621
}

0 commit comments

Comments
 (0)