Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: project 3 trait KvsEngine's fn remove #469

Open
thanhnguyen2187 opened this issue Jan 6, 2025 · 0 comments
Open

Rust: project 3 trait KvsEngine's fn remove #469

thanhnguyen2187 opened this issue Jan 6, 2025 · 0 comments
Labels
type/enhancement New feature or request

Comments

@thanhnguyen2187
Copy link

Now, the trait is:

pub trait KvsEngine: Send + Sync {
    fn set(&mut self, key: String, value: String) -> Result<()>;
    fn get(&self, key: String) -> Result<Option<String>>;
    fn remove(&mut self, key: String) -> Result<()>;
}

I think Result<()> of remove is not good typing, as it groups both key not found and other errors into one type. The signature of get is much better, as we can infer from the returned result:

  • Result(Some(...)): a corresponding value is found
  • Result(None): there is no corresponding value
  • Error(...): error happened

My proposal is to have remove returns the same type as get:

pub trait KvsEngine: Send + Sync {
    fn set(&mut self, key: String, value: String) -> Result<()>;
    fn get(&self, key: String) -> Result<Option<String>>;
    fn remove(&mut self, key: String) -> Result<Option<String>>;
}
@thanhnguyen2187 thanhnguyen2187 added the type/enhancement New feature or request label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant