Skip to content

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

@thanhnguyen2187

Description

@thanhnguyen2187

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>>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions