-
Notifications
You must be signed in to change notification settings - Fork 752
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: simplify MapApi #13063
refactor: simplify MapApi #13063
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
- Add trait `MapKey` and `MapValue` to define behavior of key values that are used in `MapApi`. - Add Ref and RefMut as container of reference to leveled data. - Collect get() and range() implementation into function. The MapApi trait can not be generalized to adapt arbitrary lifetime, such as using `self` instead of `&self`: `MapApiRO { fn get(self, key) }`. Because there is a known limitation with rust GAT and hihger ranked lifetime: See: rust-lang/rust#114046 ``` error: implementation of `MapApiRO` is not general enough --> src/meta/raft-store/src/sm_v002/sm_v002.rs:80:74 | 80 | async fn get_kv(&self, key: &str) -> Result<GetKVReply, Self::Error> { | __________________________________________________________________________^ 81 | | let got = self.sm.get_kv(key).await; 82 | | 83 | | let local_now_ms = SeqV::<()>::now_ms(); 84 | | let got = Self::non_expired(got, local_now_ms); 85 | | Ok(got) 86 | | } | |_____^ implementation of `MapApiRO` is not general enough | = note: `MapApiRO<'1, std::string::String>` would have to be implemented for the type `&'0 LevelData`, for any two lifetimes `'0` and `'1`... = note: ...but `MapApiRO<'2, std::string::String>` is actually implemented for the type `&'2 LevelData`, for some specific lifetime `'2` ```
52da1f8
to
c7a53db
Compare
I read a blog the other day where the author had written a library that claimed to workaround lifetime problems, I'm not sure if it's useful or not. |
I sincerely appreciate your assistance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy Mid-Autumn Day!
Happy National Day! |
Quite good an article. It explains in detail the causes of the issue I have had, and provides a workaround solution. The crate
|
* refactor: simplify MapApi - Add trait `MapKey` and `MapValue` to define behavior of key values that are used in `MapApi`. - Add Ref and RefMut as container of reference to leveled data. - Collect get() and range() implementation into function. The MapApi trait can not be generalized to adapt arbitrary lifetime, such as using `self` instead of `&self`: `MapApiRO { fn get(self, key) }`. Because there is a known limitation with rust GAT and hihger ranked lifetime: See: rust-lang/rust#114046 ``` error: implementation of `MapApiRO` is not general enough --> src/meta/raft-store/src/sm_v002/sm_v002.rs:80:74 | 80 | async fn get_kv(&self, key: &str) -> Result<GetKVReply, Self::Error> { | __________________________________________________________________________^ 81 | | let got = self.sm.get_kv(key).await; 82 | | 83 | | let local_now_ms = SeqV::<()>::now_ms(); 84 | | let got = Self::non_expired(got, local_now_ms); 85 | | Ok(got) 86 | | } | |_____^ implementation of `MapApiRO` is not general enough | = note: `MapApiRO<'1, std::string::String>` would have to be implemented for the type `&'0 LevelData`, for any two lifetimes `'0` and `'1`... = note: ...but `MapApiRO<'2, std::string::String>` is actually implemented for the type `&'2 LevelData`, for some specific lifetime `'2` ``` * refactor: move Ref and RefMut to separate files * refactor: rename is_not_found() to not_found() As @ariesdevil kindly suggested. * refactor: simplify map api names: LevelData to Level * chore: fix clippy
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
refactor: simplify MapApi
Add trait
MapKey
andMapValue
to define behavior of key valuesthat are used in
MapApi
.Add Ref and RefMut as container of reference to leveled data.
Collect get() and range() implementation into function.
The MapApi trait can not be generalized to adapt arbitrary lifetime,
such as using
self
instead of&self
:MapApiRO { fn get(self, key) }
.Because there is a known limitation with rust GAT and hihger ranked
lifetime: See: rust-lang/rust#114046
Changelog
Related Issues
This change is