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

purge_all allows passing in items' ownership or reference #82

Merged
merged 1 commit into from
Aug 5, 2023

Conversation

TD-Sky
Copy link
Contributor

@TD-Sky TD-Sky commented Aug 4, 2023

purge_all implementation for #54 .

The reason why accepting owned items even though we can take only references is compatibility. Refer to #65 (comment) .


This PR is not fully compatible. It would cause the scene whose type is ambiguous fails compiling, see below:

fn purge_empty() {
    // error!
    trash::os_limited::purge_all(vec![]).unwrap();
}

You need to declare the type:

fn purge_empty() {
    trash::os_limited::purge_all::<Vec<trash::TrashItem>>(vec![]).unwrap();
}

But I believe the scenes are extremely rare in practice.

@TD-Sky
Copy link
Contributor Author

TD-Sky commented Aug 4, 2023

@oberblastmeister

Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, also for pointing out possible compatibility issues.

I learned that in Rust there is a bunch of subtle breaking changes, and some code can even break when another implementation of a trait is added as all of the sudden trait resolution in the calling code is ambiguous.

The improvement is well worth the risk, so let's hope that nobody is actually calling this function with an untyped Vec.

@Byron Byron merged commit 0789b23 into Byron:master Aug 5, 2023
3 checks passed
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.

2 participants