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

Return Iterator when possible #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wiiznokes
Copy link
Contributor

  • change Option<Vec> signatures to impl Iterator<Item = &'a str>
  • use split_terminator instead of split

Equivalent to [split], except that the trailing substring is skipped if empty.

@leb-kuchen
Copy link

I am not sure about the removal of option.

@wiiznokes
Copy link
Contributor Author

This is kinda necessary if we want to return an opaque Iterator, because before we used

let b = entry.mime_type().unwrap_or_default().iter().any(|m|m == "f");

And with an option:

entry.mime_type().map(|i| i.any(|m|m == "f")).unwrap_or(false);

instead of

let b = entry.mime_type().any(|m|m == "f");

I don't really see an use case to handle the case where the field is not defined, but if someone want to handle it, he could use his own functions.

@leb-kuchen
Copy link

I don't think .unwrap_or_else(|| "".split_terminator(';')) or into_iter().flatten() is difficult to write.
If it is intuitive and there are not any use cases, it may be still be worth to remove the Option,

I think SplitTerminator should be returned instead of an opaque type. This way .into_remainder() can be used to get the actual string.

@wiiznokes
Copy link
Contributor Author

I think SplitTerminator should be returned instead of an opaque type. This way rust-lang/rust#77998 can be used to get the actual string

Yeah good idea

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