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

Refactor push_value_ref() method in MutableVector trait #978

Closed
Tracked by #555
evenyag opened this issue Feb 13, 2023 · 1 comment · Fixed by #987
Closed
Tracked by #555

Refactor push_value_ref() method in MutableVector trait #978

evenyag opened this issue Feb 13, 2023 · 1 comment · Fixed by #987
Assignees
Labels
C-enhancement Category Enhancements good first issue Good for newcomers

Comments

@evenyag
Copy link
Contributor

evenyag commented Feb 13, 2023

Now using MutableVector::push_value_ref is verbose as callers always need to handle the returned Result.

fn push_value_ref(&mut self, value: ValueRef) -> Result<()>;

Most times, callers ensure that the pushed value ref has a valid data type. But they still need to add a safety note in the comment and unwrap the result manually.

// Safety: Both the vector and default value are created by the data type.
mutable_vector.push_value_ref(value_ref).unwrap();

Consider refactoring the MutableVector and changing the push_value_ref() to panic by default (with panic section in doc comments). We could rename the old push_value_ref() method to try_push_value_ref().

trait MutableVector {
    fn try_push_value_ref(&mut self, value: ValueRef) -> Result<()>; 

    fn push_value_ref(&mut self, value: ValueRef) -> Result<()> {
        self.try_push_value_ref(value).unwrap()
    }

    fn push_null(&mut self);
}

We could also add a push_null method to make pushing null more convenient

vector
.push_value_ref(ValueRef::Null)
.context(CreateVectorSnafu)?;

@evenyag evenyag changed the title Wrap push_value_ref().unwrap() for MutableVector Refactor push_value_ref() method in MutableVector trait Feb 13, 2023
@evenyag evenyag added C-enhancement Category Enhancements good first issue Good for newcomers labels Feb 13, 2023
@etolbakov
Copy link
Collaborator

@evenyag I would like to give it a try if you don't mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category Enhancements good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants