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

Prefer const/statics when possible #2

Open
burdges opened this issue Feb 11, 2021 · 1 comment
Open

Prefer const/statics when possible #2

burdges opened this issue Feb 11, 2021 · 1 comment

Comments

@burdges
Copy link

burdges commented Feb 11, 2021

I learned about this create from https://users.rust-lang.org/t/ron-are-there-crates-to-serialize-rust-types-as-correctly-formated-rust-code/55451

Could one prefer const/static forms when they exist?

As a type level example, if T could be converted to 'static then Cow<'a,T> should be replaced by Cow<'static,T>.

As a value level, both Cow::Owned(Box<[T]>) and Cow::Borrowed(&'a [T]) should be replaced by Cow::Borrowed(&'static [T]).

There might exist users who'd wish to forbid allocations like Vec<T> etc. entirely too, but almost anyone using uneval should replace String with Cow<'static,str> and replace Vec<T> with Cow<'static,[T]>.

@burdges
Copy link
Author

burdges commented Feb 11, 2021

Appears you serialize all allocated types with vec![..].into_iter().collect(), which should probably be &'static [..].into_iter().collect().

It appears serde fully dereferences any Deref types, so Cow breaks uneval: https://github.com/burdges/uneval/blob/cow/examples/cow_test.rs

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

No branches or pull requests

1 participant