Skip to content

Commit

Permalink
Normalize the extentions inside of config in-place
Browse files Browse the repository at this point in the history
* Rename `update_extentions` to `Normalize_extentions` as it better conveys the intent;
* Remove the unnecessary copy of the extensions vector;
* Remove the unnecessary copy of the `RustusConf` object;
  • Loading branch information
Kolaer committed Jan 11, 2023
1 parent 806bc34 commit 805eb8f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ impl RustusConf {
/// This is a workaround for issue mentioned
/// [here](https://www.reddit.com/r/rust/comments/8ddd19/confusion_with_splitting_mainrs_into_smaller/).
pub fn from_args() -> RustusConf {
<RustusConf as StructOpt>::from_args().update_extensions()
let mut conf = <RustusConf as StructOpt>::from_args();
conf.normalize_extentions();
conf
}

pub fn from_iter<I>(iter: I) -> RustusConf
Expand Down Expand Up @@ -363,17 +365,17 @@ impl RustusConf {
self.notification_opts.hooks.contains(&hook)
}

/// Update extension vec.
/// Normalize extension vec.
///
/// This function will parse list of extensions from CLI
/// and sort them.
/// Nomralization consists of two parts:
/// 1. Adding dependent extentions (e.g. creation-with-upload depends on creation);
/// 2. Sorting the resulting extentions;
///
/// Protocol extensions must be sorted,
/// because Actix doesn't override
/// existing methods.
pub fn update_extensions(self) -> Self {
let mut ext = self.tus_extensions.clone();

pub fn normalize_extentions(&mut self) {
let ext = &mut self.tus_extensions;
// If create-with-upload extension is enabled
// creation extension must be enabled too.
if ext.contains(&Extensions::CreationWithUpload) && !ext.contains(&Extensions::Creation) {
Expand All @@ -387,9 +389,5 @@ impl RustusConf {
}

ext.sort();
Self {
tus_extensions: ext,
..self
}
}
}

0 comments on commit 805eb8f

Please sign in to comment.