Skip to content

flatten and flatten_ref methods on ActiveValue#3146

Open
PacificBird wants to merge 3 commits into
SeaQL:masterfrom
PacificBird:flatten_as_ref
Open

flatten and flatten_ref methods on ActiveValue#3146
PacificBird wants to merge 3 commits into
SeaQL:masterfrom
PacificBird:flatten_as_ref

Conversation

@PacificBird

Copy link
Copy Markdown
Contributor

Closes #3145

@Huliiiiii

Copy link
Copy Markdown
Member

Why not just:

impl<V> ActiveValue<Option<V>>
where
    V: Into<Value> + Nullable, 
{
...
}

@Huliiiiii

Copy link
Copy Markdown
Member

Naming them as_option and into_option might be better.

@PacificBird

Copy link
Copy Markdown
Contributor Author

Why not just:

impl<V> ActiveValue<Option<V>>
where
    V: Into<Value> + Nullable, 
{
...
}

This requires specialization afaik. The impl<V> ActiveValue<V> gives a conflicting implementation as far as the compiler is currently concerned.

@PacificBird

Copy link
Copy Markdown
Contributor Author

Naming them as_option and into_option might be better.

That's definitely shorter and nicer.

@Huliiiiii

Huliiiiii commented Jul 24, 2026

Copy link
Copy Markdown
Member

Why not just:

impl<V> ActiveValue<Option<V>>
where
    V: Into<Value> + Nullable, 
{
...
}

This requires specialization afaik. The impl<V> ActiveValue<V> gives a conflicting implementation as far as the compiler is currently concerned.

Implementing it on Option<V> instead of V works correctly. (on my machine)

impl<V> ActiveValue<Option<V>>
where
    V: Into<Value> + Nullable,
{
    pub fn as_option(&self) -> Option<&V> {
        self.try_as_ref().and_then(Option::as_ref)
    }
 
    pub fn into_option(self) -> Option<V> {
        match self {
            Self::Set(value) | Self::Unchanged(value) => value,
            Self::NotSet => None,
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flatten methods on ActiveValue

2 participants