Skip to content

Commit

Permalink
Fix rust
Browse files Browse the repository at this point in the history
  • Loading branch information
unimonkiez committed Dec 12, 2024
1 parent 11197d8 commit c82b5a5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions clients/redis/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ pub struct Hide;

#[derive(Clone)]
pub enum Value {
String { value: String },
EnvVariable { name: String, value: Option<String> },
String {
value: &'static str,
},
EnvVariable {
name: &'static str,
value: Option<String>,
},
}

impl Value {
pub fn from_string(value: String) -> Self {
pub fn from_string(value: &'static str) -> Self {
Self::String { value }
}
pub fn from_env_variable(name: String) -> Self {
pub fn from_env_variable(name: &'static str) -> Self {
let value = std::env::var(&name).ok();
Self::EnvVariable { name, value }
}
fn require(&self) -> Result<String, Box<dyn std::error::Error + Sync + Send>> {
match self {
Self::String { value } => Ok(value.clone()),
Self::String { value } => Ok((*value).to_string()),
Self::EnvVariable { name, value } => Ok(value
.clone()
.ok_or(format!("Environment variable \"{name}\" is not set"))?),
Expand Down Expand Up @@ -115,10 +120,10 @@ pub struct MemorixBase {

impl MemorixBase {
pub async fn new(
redis_url: &str,
redis_url: &Value,
namespace_name_tree: &'static [&'static str],
) -> Result<MemorixBase, Box<dyn std::error::Error + Sync + Send>> {
let client = redis::Client::open(redis_url)?;
let client = redis::Client::open(redis_url.require()?)?;
let redis = client.get_multiplexed_async_connection().await?;
let task_redis = client.get_multiplexed_async_connection().await?;
Ok(Self {
Expand Down

0 comments on commit c82b5a5

Please sign in to comment.