Skip to content

Commit 0882e7d

Browse files
committed
Rename write_single and write_multiple to write_full and write_partial respectively.
1 parent 5cfc543 commit 0882e7d

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
@@ -866,7 +866,7 @@ impl AssetProcessor {
866866
}
867867
{
868868
// If this directory has a meta file, then it is likely a processed asset using
869-
// `ProcessContext::write_multiple`, so count the whole thing as an asset path.
869+
// `ProcessContext::write_partial`, so count the whole thing as an asset path.
870870
paths.push(path);
871871
return Ok(true);
872872
}
@@ -1278,7 +1278,7 @@ impl AssetProcessor {
12781278

12791279
let mut started_writes = 0;
12801280
let mut finished_writes = AtomicU32::new(0);
1281-
let mut single_meta = None;
1281+
let mut full_meta = None;
12821282
processor
12831283
.process(
12841284
&mut ProcessContext::new(
@@ -1292,7 +1292,7 @@ impl AssetProcessor {
12921292
processed_writer,
12931293
&mut started_writes,
12941294
&mut finished_writes,
1295-
&mut single_meta,
1295+
&mut full_meta,
12961296
asset_path,
12971297
),
12981298
)
@@ -1311,7 +1311,7 @@ impl AssetProcessor {
13111311
.iter()
13121312
.map(|i| i.full_hash),
13131313
);
1314-
let mut processed_meta = single_meta
1314+
let mut processed_meta = full_meta
13151315
.unwrap_or_else(|| Box::new(AssetMeta::<(), ()>::new(AssetAction::Decomposed)));
13161316

13171317
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)
@@ -385,18 +385,18 @@ pub struct WriterContext<'a> {
385385
/// The underlying writer of all writes for the [`Process`].
386386
writer: &'a dyn ErasedAssetWriter,
387387
/// The context for initializing a write.
388-
// We use a Mutex to avoid requiring a mutable borrow for `write_multiple`. See `write_multiple`
388+
// We use a Mutex to avoid requiring a mutable borrow for `write_partial`. See `write_partial`
389389
// for more details.
390390
init_context: Mutex<WriteInitContext<'a>>,
391391
/// The number of writes that have been fully finished.
392392
///
393393
/// Note we use an `AtomicU32` instead of a u32 so that writes (and therefore finish's) don't
394-
/// need to be synchronous. We use a mutable borrow so that single-writes can just update the
394+
/// need to be synchronous. We use a mutable borrow so that full-writes can just update the
395395
/// value without atomics.
396396
finished_writes: &'a mut AtomicU32,
397397
/// The meta object to write when writing a single file. Must be set to [`Some`] when writing a
398-
/// single file.
399-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
398+
/// "full" file.
399+
full_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
400400
/// The path of the asset being processed.
401401
path: &'a AssetPath<'static>,
402402
}
@@ -405,7 +405,7 @@ pub struct WriterContext<'a> {
405405
struct WriteInitContext<'a> {
406406
/// The number of writes that have been started.
407407
started_writes: &'a mut u32,
408-
/// The set of currently started `write_multiple` instances.
408+
/// The set of currently started [`WriterContext::write_partial`] instances.
409409
///
410410
/// This protects us from starting writes for the same path multiple times.
411411
started_paths: HashSet<PathBuf>,
@@ -416,7 +416,7 @@ impl<'a> WriterContext<'a> {
416416
writer: &'a dyn ErasedAssetWriter,
417417
started_writes: &'a mut u32,
418418
finished_writes: &'a mut AtomicU32,
419-
single_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
419+
full_meta: &'a mut Option<Box<dyn AssetMetaDyn>>,
420420
path: &'a AssetPath<'static>,
421421
) -> Self {
422422
Self {
@@ -426,23 +426,23 @@ impl<'a> WriterContext<'a> {
426426
started_paths: HashSet::new(),
427427
}),
428428
finished_writes,
429-
single_meta,
429+
full_meta,
430430
path,
431431
}
432432
}
433433

434434
/// Start writing a single output file, which can be loaded with the `load_settings`.
435435
///
436-
/// Returns an error if you have previously called [`Self::write_multiple`].
437-
pub async fn write_single(self) -> Result<SingleWriter<'a>, ProcessError> {
436+
/// Returns an error if you have previously called [`Self::write_partial`].
437+
pub async fn write_full(self) -> Result<FullWriter<'a>, ProcessError> {
438438
let started_writes = self
439439
.init_context
440440
.into_inner()
441441
.unwrap_or_else(PoisonError::into_inner)
442442
.started_writes;
443443
if *started_writes != 0 {
444444
return Err(ProcessError::InvalidProcessOutput(
445-
InvalidProcessOutput::SingleFileAfterMultipleFile,
445+
InvalidProcessOutput::FullFileAfterPartialFile,
446446
));
447447
}
448448
*started_writes = 1;
@@ -453,21 +453,19 @@ impl<'a> WriterContext<'a> {
453453
err,
454454
}
455455
})?;
456-
Ok(SingleWriter {
456+
Ok(FullWriter {
457457
writer,
458458
finished_writes: self.finished_writes.get_mut(),
459459
path: self.path,
460-
single_meta: self.single_meta,
460+
meta: self.full_meta,
461461
})
462462
}
463463

464-
/// Start writing one of multiple output file, which can be loaded with the `load_settings`.
465-
///
466-
/// Returns an error if you have previously started writing a single file.
464+
/// Start writing one of multiple output files, which can be loaded with the `load_settings`.
467465
// Note: It would be nice to take this by a mutable reference instead. However, doing so would
468466
// mean that the returned value would be tied to a "mutable reference lifetime", meaning we
469-
// could not use more than one `MultipleWriter` instance concurrently.
470-
pub async fn write_multiple(&self, file: &Path) -> Result<MultipleWriter<'_>, ProcessError> {
467+
// could not use more than one `PartialWriter` instance concurrently.
468+
pub async fn write_partial(&self, file: &Path) -> Result<PartialWriter<'_>, ProcessError> {
471469
// Do all the validation in a scope so we don't hold the init_context for too long.
472470
{
473471
let mut init_context = self
@@ -477,7 +475,7 @@ impl<'a> WriterContext<'a> {
477475
// Check whether this path is valid first so that we don't mark the write as started
478476
// when it hasn't.
479477
if !init_context.started_paths.insert(file.to_path_buf()) {
480-
return Err(InvalidProcessOutput::RepeatedMultipleWriteToSamePath(
478+
return Err(InvalidProcessOutput::RepeatedPartialWriteToSamePath(
481479
file.to_path_buf(),
482480
)
483481
.into());
@@ -501,7 +499,7 @@ impl<'a> WriterContext<'a> {
501499
path: path.clone_owned(),
502500
err,
503501
})?;
504-
Ok(MultipleWriter {
502+
Ok(PartialWriter {
505503
meta_writer: self.writer,
506504
writer,
507505
finished_writes: &*self.finished_writes,
@@ -514,32 +512,34 @@ impl<'a> WriterContext<'a> {
514512
#[derive(Error, Debug)]
515513
pub enum InvalidProcessOutput {
516514
/// The processor didn't start a write at all.
517-
#[error("The processor never started writing a file (never called `write_single` or `write_multiple`)")]
515+
#[error(
516+
"The processor never started writing a file (never called `write_full` or `write_partial`)"
517+
)]
518518
NoWriter,
519519
/// The processor started a write but never finished it.
520520
#[error("The processor started writing a file, but never called `finish`")]
521521
UnfinishedWriter,
522-
/// The processor started at least one multiple write, then continued with a single write.
523-
#[error("The processor called `write_single` after already calling `write_multiple`")]
524-
SingleFileAfterMultipleFile,
525-
/// The processor started a multiple write with the same path multiple times.
526-
#[error("The processor called `write_multiple` more than once with the same path")]
527-
RepeatedMultipleWriteToSamePath(PathBuf),
522+
/// The processor started at least one partial write, then continued with a full write.
523+
#[error("The processor called `write_full` after already calling `write_partial`")]
524+
FullFileAfterPartialFile,
525+
/// The processor started a partial write with the same path multiple times.
526+
#[error("The processor called `write_partial` more than once with the same path")]
527+
RepeatedPartialWriteToSamePath(PathBuf),
528528
}
529529

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

542-
impl SingleWriter<'_> {
542+
impl FullWriter<'_> {
543543
/// Finishes a write and indicates that the written asset should be loaded with the provided
544544
/// loader and the provided settings for that loader.
545545
///
@@ -563,8 +563,8 @@ impl SingleWriter<'_> {
563563

564564
// This should always be none, since we consumed the WriterContext, and we consume the
565565
// only borrow here.
566-
assert!(self.single_meta.is_none());
567-
*self.single_meta = Some(Box::new(output_meta));
566+
assert!(self.meta.is_none());
567+
*self.meta = Some(Box::new(output_meta));
568568

569569
// Make sure to increment finished writes at the very end, so that we only count it, once
570570
// the future is finished anyway.
@@ -573,8 +573,9 @@ impl SingleWriter<'_> {
573573
}
574574
}
575575

576-
/// A writer for a [`Process`] writing multiple files (as children of the unprocessed asset path).
577-
pub struct MultipleWriter<'a> {
576+
/// A writer for a [`Process`] writing multiple partial files (as children of the unprocessed asset
577+
/// path).
578+
pub struct PartialWriter<'a> {
578579
/// The writer to use when writing the meta file for this file.
579580
meta_writer: &'a dyn ErasedAssetWriter,
580581
/// The writer to write to.
@@ -587,7 +588,7 @@ pub struct MultipleWriter<'a> {
587588
path: AssetPath<'static>,
588589
}
589590

590-
impl MultipleWriter<'_> {
591+
impl PartialWriter<'_> {
591592
/// Finishes a write and indicates that the written asset should be loaded with the provided
592593
/// loader and the provided settings for that loader.
593594
///
@@ -630,29 +631,29 @@ impl MultipleWriter<'_> {
630631
}
631632
}
632633

633-
impl Deref for SingleWriter<'_> {
634+
impl Deref for FullWriter<'_> {
634635
type Target = Writer;
635636

636637
fn deref(&self) -> &Self::Target {
637638
self.writer.as_ref()
638639
}
639640
}
640641

641-
impl DerefMut for SingleWriter<'_> {
642+
impl DerefMut for FullWriter<'_> {
642643
fn deref_mut(&mut self) -> &mut Self::Target {
643644
self.writer.as_mut()
644645
}
645646
}
646647

647-
impl Deref for MultipleWriter<'_> {
648+
impl Deref for PartialWriter<'_> {
648649
type Target = Writer;
649650

650651
fn deref(&self) -> &Self::Target {
651652
self.writer.as_ref()
652653
}
653654
}
654655

655-
impl DerefMut for MultipleWriter<'_> {
656+
impl DerefMut for PartialWriter<'_> {
656657
fn deref_mut(&mut self) -> &mut Self::Target {
657658
self.writer.as_mut()
658659
}

0 commit comments

Comments
 (0)