From fa1c5a84ece937b4fc134e78067018ec6b4f246a Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Mon, 10 Oct 2022 17:08:58 -0700 Subject: [PATCH] Use BTreeSet instead of BTreeMap --- src/generator/templates/api/api.rs.mako | 2 +- src/generator/templates/api/lib/mbuild.mako | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/generator/templates/api/api.rs.mako b/src/generator/templates/api/api.rs.mako index cf15ee2aff..9f58e0cdee 100644 --- a/src/generator/templates/api/api.rs.mako +++ b/src/generator/templates/api/api.rs.mako @@ -18,7 +18,7 @@ use std::collections::HashMap; use std::cell::RefCell; use std::default::Default; -use std::collections::BTreeMap; +use std::collections::BTreeSet; use std::error::Error as StdError; use serde_json as json; use std::io; diff --git a/src/generator/templates/api/lib/mbuild.mako b/src/generator/templates/api/lib/mbuild.mako index e6db099470..90fde7b508 100644 --- a/src/generator/templates/api/lib/mbuild.mako +++ b/src/generator/templates/api/lib/mbuild.mako @@ -126,7 +126,7 @@ pub struct ${ThisType} ${api.properties.params}: HashMap, % if method_default_scope(m): ## We need the scopes sorted, to not unnecessarily query new tokens - ${api.properties.scopes}: BTreeMap + ${api.properties.scopes}: BTreeSet % endif } @@ -188,9 +188,8 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ pub fn ${ADD_SCOPE_FN}(mut self, scope: T) -> ${ThisType} where T: Into>, St: AsRef { - match scope.into() { - Some(scope) => self.${api.properties.scopes}.insert(scope.as_ref().to_string(), ()), - None => None, + if let Some(scope) = scope.into() { + self.${api.properties.scopes}.insert(scope.as_ref().to_string()); }; self } @@ -637,8 +636,8 @@ else { } % endif % else: - if self.${api.properties.scopes}.len() == 0 { - self.${api.properties.scopes}.insert(${scope_url_to_variant(name, default_scope, fully_qualified=True)}.as_ref().to_string(), ()); + if self.${api.properties.scopes}.is_empty() { + self.${api.properties.scopes}.insert(${scope_url_to_variant(name, default_scope, fully_qualified=True)}.as_ref().to_string()); } % endif @@ -707,7 +706,7 @@ else { loop { % if default_scope: - let token = match ${auth_call}.get_token(&self.${api.properties.scopes}.keys().map(String::as_str).collect::>()[..]).await { + let token = match ${auth_call}.get_token(&self.${api.properties.scopes}.iter().map(String::as_str).collect::>()[..]).await { // TODO: remove Ok / Err branches Ok(Some(token)) => token.clone(), Ok(None) => {