Skip to content

Commit

Permalink
Refactor env contains into separate api
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed <>
  • Loading branch information
Ahmed committed Sep 21, 2024
1 parent c8bc3a8 commit c4bbfd4
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions env/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ impl<T> Environment<T> {
}
true
}

#[must_use]
pub fn contains(&self, key: &str) -> bool {
self.data.contains_key(key)
}
pub fn add_str_with_cb(
&mut self,
key: &str,
Expand All @@ -55,7 +58,7 @@ impl<T> Environment<T> {
data: &mut T,
cb: StrFn<T>,
) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvStr {
Expand All @@ -73,7 +76,7 @@ impl<T> Environment<T> {
}

pub fn add_str(&mut self, key: &str, val: &str, help: &str) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvStr {
Expand Down Expand Up @@ -140,7 +143,7 @@ impl<T> Environment<T> {
data: &mut T,
cb: U64Fn<T>,
) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvU64 {
Expand All @@ -158,7 +161,7 @@ impl<T> Environment<T> {
}

pub fn add_u64(&mut self, key: &str, val: u64, help: &str) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvU64 {
Expand Down Expand Up @@ -225,7 +228,7 @@ impl<T> Environment<T> {
data: &mut T,
cb: I64Fn<T>,
) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvI64 {
Expand All @@ -243,7 +246,7 @@ impl<T> Environment<T> {
}

pub fn add_i64(&mut self, key: &str, val: i64, help: &str) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvI64 {
Expand Down Expand Up @@ -310,7 +313,7 @@ impl<T> Environment<T> {
data: &mut T,
cb: BoolFn<T>,
) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvBool {
Expand All @@ -328,7 +331,7 @@ impl<T> Environment<T> {
}

pub fn add_bool(&mut self, key: &str, val: bool, help: &str) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvBool {
Expand Down Expand Up @@ -395,7 +398,7 @@ impl<T> Environment<T> {
data: &mut T,
cb: ColorFn<T>,
) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvColor {
Expand All @@ -413,7 +416,7 @@ impl<T> Environment<T> {
}

pub fn add_color(&mut self, key: &str, val: (u8, u8, u8), help: &str) -> Result<(), EnvErr> {
if self.data.contains_key(key) {
if self.contains(key) {
return Err(EnvErr::AlreadyExist);
}
let meta = EnvColor {
Expand Down

0 comments on commit c4bbfd4

Please sign in to comment.