Skip to content

Commit ba4baa4

Browse files
committed
Rename write_single and write_multiple to write_full and write_partial respectively.
1 parent 1c757aa commit ba4baa4

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
@@ -862,7 +862,7 @@ impl AssetProcessor {
862862
}
863863
{
864864
// If this directory has a meta file, then it is likely a processed asset using
865-
// `ProcessContext::write_multiple`, so count the whole thing as an asset path.
865+
// `ProcessContext::write_partial`, so count the whole thing as an asset path.
866866
paths.push(path);
867867
return Ok(true);
868868
}
@@ -1274,7 +1274,7 @@ impl AssetProcessor {
12741274

12751275
let mut started_writes = 0;
12761276
let mut finished_writes = AtomicU32::new(0);
1277-
let mut single_meta = None;
1277+
let mut full_meta = None;
12781278
{
12791279
let mut context = ProcessContext::new(
12801280
self,
@@ -1289,7 +1289,7 @@ impl AssetProcessor {
12891289
processed_writer,
12901290
&mut started_writes,
12911291
&mut finished_writes,
1292-
&mut single_meta,
1292+
&mut full_meta,
12931293
asset_path,
12941294
),
12951295
);
@@ -1318,7 +1318,7 @@ impl AssetProcessor {
13181318
.iter()
13191319
.map(|i| i.full_hash),
13201320
);
1321-
let mut processed_meta = single_meta
1321+
let mut processed_meta = full_meta
13221322
.unwrap_or_else(|| Box::new(AssetMeta::<(), ()>::new(AssetAction::Decomposed)));
13231323

13241324
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
@@ -215,7 +215,7 @@ where
215215

216216
let saver = &self.saver;
217217
let saver_settings = &settings.saver_settings;
218-
let mut writer = writer_context.write_single().await?;
218+
let mut writer = writer_context.write_full().await?;
219219

220220
let output_settings = saver
221221
.save(&mut *writer, saved_asset, saver_settings)
@@ -391,18 +391,18 @@ pub struct WriterContext<'a> {
391391
/// The underlying writer of all writes for the [`Process`].
392392
writer: &'a dyn ErasedAssetWriter,
393393
/// The context for initializing a write.
394-
// We use a Mutex to avoid requiring a mutable borrow for `write_multiple`. See `write_multiple`
394+
// We use a Mutex to avoid requiring a mutable borrow for `write_partial`. See `write_partial`
395395
// for more details.
396396
init_context: Mutex<WriteInitContext<'a>>,
397397
/// The number of writes that have been fully finished.
398398
///
399399
/// Note we use an `AtomicU32` instead of a u32 so that writes (and therefore finish's) don't
400-
/// need to be synchronous. We use a mutable borrow so that single-writes can just update the
400+
/// need to be synchronous. We use a mutable borrow so that full-writes can just update the
401401
/// value without atomics.
402402
finished_writes: &'a mut AtomicU32,
403403
/// The meta object to write when writing a single file. Must be set to [`Some`] when writing a
404-
/// single file.
405-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
404+
/// "full" file.
405+
full_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
406406
/// The path of the asset being processed.
407407
path: &'a AssetPath<'static>,
408408
}
@@ -411,7 +411,7 @@ pub struct WriterContext<'a> {
411411
struct WriteInitContext<'a> {
412412
/// The number of writes that have been started.
413413
started_writes: &'a mut u32,
414-
/// The set of currently started `write_multiple` instances.
414+
/// The set of currently started [`WriterContext::write_partial`] instances.
415415
///
416416
/// This protects us from starting writes for the same path multiple times.
417417
started_paths: HashSet<PathBuf>,
@@ -422,7 +422,7 @@ impl<'a> WriterContext<'a> {
422422
writer: &'a dyn ErasedAssetWriter,
423423
started_writes: &'a mut u32,
424424
finished_writes: &'a mut AtomicU32,
425-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
425+
full_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
426426
path: &'a AssetPath<'static>,
427427
) -> Self {
428428
Self {
@@ -432,23 +432,23 @@ impl<'a> WriterContext<'a> {
432432
started_paths: HashSet::new(),
433433
}),
434434
finished_writes,
435-
single_meta,
435+
full_meta,
436436
path,
437437
}
438438
}
439439

440440
/// Start writing a single output file, which can be loaded with the `load_settings`.
441441
///
442-
/// Returns an error if you have previously called [`Self::write_multiple`].
443-
pub async fn write_single(self) -> Result<SingleWriter<'a>, ProcessError> {
442+
/// Returns an error if you have previously called [`Self::write_partial`].
443+
pub async fn write_full(self) -> Result<FullWriter<'a>, ProcessError> {
444444
let started_writes = self
445445
.init_context
446446
.into_inner()
447447
.unwrap_or_else(PoisonError::into_inner)
448448
.started_writes;
449449
if *started_writes != 0 {
450450
return Err(ProcessError::InvalidProcessOutput(
451-
InvalidProcessOutput::SingleFileAfterMultipleFile,
451+
InvalidProcessOutput::FullFileAfterPartialFile,
452452
));
453453
}
454454
*started_writes = 1;
@@ -459,21 +459,19 @@ impl<'a> WriterContext<'a> {
459459
err,
460460
}
461461
})?;
462-
Ok(SingleWriter {
462+
Ok(FullWriter {
463463
writer,
464464
finished_writes: self.finished_writes.get_mut(),
465465
path: self.path,
466-
single_meta: self.single_meta,
466+
meta: self.full_meta,
467467
})
468468
}
469469

470-
/// Start writing one of multiple output file, which can be loaded with the `load_settings`.
471-
///
472-
/// Returns an error if you have previously started writing a single file.
470+
/// Start writing one of multiple output files, which can be loaded with the `load_settings`.
473471
// Note: It would be nice to take this by a mutable reference instead. However, doing so would
474472
// mean that the returned value would be tied to a "mutable reference lifetime", meaning we
475-
// could not use more than one `MultipleWriter` instance concurrently.
476-
pub async fn write_multiple(&self, file: &Path) -> Result<MultipleWriter<'_>, ProcessError> {
473+
// could not use more than one `PartialWriter` instance concurrently.
474+
pub async fn write_partial(&self, file: &Path) -> Result<PartialWriter<'_>, ProcessError> {
477475
// Do all the validation in a scope so we don't hold the init_context for too long.
478476
{
479477
let mut init_context = self
@@ -483,7 +481,7 @@ impl<'a> WriterContext<'a> {
483481
// Check whether this path is valid first so that we don't mark the write as started
484482
// when it hasn't.
485483
if !init_context.started_paths.insert(file.to_path_buf()) {
486-
return Err(InvalidProcessOutput::RepeatedMultipleWriteToSamePath(
484+
return Err(InvalidProcessOutput::RepeatedPartialWriteToSamePath(
487485
file.to_path_buf(),
488486
)
489487
.into());
@@ -507,7 +505,7 @@ impl<'a> WriterContext<'a> {
507505
path: path.clone_owned(),
508506
err,
509507
})?;
510-
Ok(MultipleWriter {
508+
Ok(PartialWriter {
511509
meta_writer: self.writer,
512510
writer,
513511
finished_writes: &*self.finished_writes,
@@ -520,32 +518,34 @@ impl<'a> WriterContext<'a> {
520518
#[derive(Error, Debug)]
521519
pub enum InvalidProcessOutput {
522520
/// The processor didn't start a write at all.
523-
#[error("The processor never started writing a file (never called `write_single` or `write_multiple`)")]
521+
#[error(
522+
"The processor never started writing a file (never called `write_full` or `write_partial`)"
523+
)]
524524
NoWriter,
525525
/// The processor started a write but never finished it.
526526
#[error("The processor started writing a file, but never called `finish`")]
527527
UnfinishedWriter,
528-
/// The processor started at least one multiple write, then continued with a single write.
529-
#[error("The processor called `write_single` after already calling `write_multiple`")]
530-
SingleFileAfterMultipleFile,
531-
/// The processor started a multiple write with the same path multiple times.
532-
#[error("The processor called `write_multiple` more than once with the same path")]
533-
RepeatedMultipleWriteToSamePath(PathBuf),
528+
/// The processor started at least one partial write, then continued with a full write.
529+
#[error("The processor called `write_full` after already calling `write_partial`")]
530+
FullFileAfterPartialFile,
531+
/// The processor started a partial write with the same path multiple times.
532+
#[error("The processor called `write_partial` more than once with the same path")]
533+
RepeatedPartialWriteToSamePath(PathBuf),
534534
}
535535

536536
/// The writer for a [`Process`] writing a single file (at the same path as the unprocessed asset).
537-
pub struct SingleWriter<'a> {
537+
pub struct FullWriter<'a> {
538538
/// The writer to write to.
539539
writer: Box<Writer>,
540540
/// The counter for finished writes that will be incremented when the write completes.
541541
finished_writes: &'a mut u32,
542542
/// The meta object that will be assigned on [`Self::finish`].
543-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
543+
meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
544544
/// The path of the asset being written.
545545
path: &'a AssetPath<'static>,
546546
}
547547

548-
impl SingleWriter<'_> {
548+
impl FullWriter<'_> {
549549
/// Finishes a write and indicates that the written asset should be loaded with the provided
550550
/// loader and the provided settings for that loader.
551551
///
@@ -569,8 +569,8 @@ impl SingleWriter<'_> {
569569

570570
// This should always be none, since we consumed the WriterContext, and we consume the
571571
// only borrow here.
572-
assert!(self.single_meta.is_none());
573-
*self.single_meta = Some(Box::new(output_meta));
572+
assert!(self.meta.is_none());
573+
*self.meta = Some(Box::new(output_meta));
574574

575575
// Make sure to increment finished writes at the very end, so that we only count it, once
576576
// the future is finished anyway.
@@ -579,8 +579,9 @@ impl SingleWriter<'_> {
579579
}
580580
}
581581

582-
/// A writer for a [`Process`] writing multiple files (as children of the unprocessed asset path).
583-
pub struct MultipleWriter<'a> {
582+
/// A writer for a [`Process`] writing multiple partial files (as children of the unprocessed asset
583+
/// path).
584+
pub struct PartialWriter<'a> {
584585
/// The writer to use when writing the meta file for this file.
585586
meta_writer: &'a dyn ErasedAssetWriter,
586587
/// The writer to write to.
@@ -593,7 +594,7 @@ pub struct MultipleWriter<'a> {
593594
path: AssetPath<'static>,
594595
}
595596

596-
impl MultipleWriter<'_> {
597+
impl PartialWriter<'_> {
597598
/// Finishes a write and indicates that the written asset should be loaded with the provided
598599
/// loader and the provided settings for that loader.
599600
///
@@ -636,29 +637,29 @@ impl MultipleWriter<'_> {
636637
}
637638
}
638639

639-
impl Deref for SingleWriter<'_> {
640+
impl Deref for FullWriter<'_> {
640641
type Target = Writer;
641642

642643
fn deref(&self) -> &Self::Target {
643644
self.writer.as_ref()
644645
}
645646
}
646647

647-
impl DerefMut for SingleWriter<'_> {
648+
impl DerefMut for FullWriter<'_> {
648649
fn deref_mut(&mut self) -> &mut Self::Target {
649650
self.writer.as_mut()
650651
}
651652
}
652653

653-
impl Deref for MultipleWriter<'_> {
654+
impl Deref for PartialWriter<'_> {
654655
type Target = Writer;
655656

656657
fn deref(&self) -> &Self::Target {
657658
self.writer.as_ref()
658659
}
659660
}
660661

661-
impl DerefMut for MultipleWriter<'_> {
662+
impl DerefMut for PartialWriter<'_> {
662663
fn deref_mut(&mut self) -> &mut Self::Target {
663664
self.writer.as_mut()
664665
}

0 commit comments

Comments
 (0)