cloudwego / metainfo Goto Github PK
View Code? Open in Web Editor NEWTransmissing metainfo across components.
Home Page: https://crates.io/crates/metainfo
License: Apache License 2.0
Transmissing metainfo across components.
Home Page: https://crates.io/crates/metainfo
License: Apache License 2.0
kv.rs 文件中,关于宏的实现使用疑惑
set_impl!(persistent);
set_impl!(transient);
set_impl!(stale);
del_impl!(persistent);
del_impl!(transient);
del_impl!(stale);
get_impl!(persistent);
get_impl!(transient);
get_impl!(stale);
get_all_impl!(persistent);
get_all_impl!(transient);
get_all_impl!(stale);
为啥不改成一个宏实现?是跟性能相关吗?
macro_rules! make_setters_and_getters {
($($field:ident),*) => {
paste! {
$(
pub fn [<set_ $field>]<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(
&mut self,
key: K,
value: V,
) {
if self.$field.is_none() {
self.$field = Some(HashMap::with_capacity(DEFAULT_CAPACITY));
}
self.$field.as_mut().unwrap().insert(key.into(), value.into());
}
pub fn [<del_ $field>]<K: AsRef<str>>(&mut self, key: K) {
let key = key.as_ref();
if let Some(v) = self.$field.as_mut() {
v.remove(key);
}
}
pub fn [<get_ $field>]<K: AsRef<str>>(&self, key: K) -> Option<&str> {
let key = key.as_ref();
match self.$field.as_ref() {
Some(v) => {
v.get(key).map(|v| v.as_ref())
}
None => None,
}
}
pub fn [<get_all_ $field s>](&self) -> Option<&HashMap<Cow<'static, str>, Cow<'static, str>>> {
self.$field.as_ref()
}
)*
}
}
}
impl Node {
make_setters_and_getters!(persistent, transient, stale);
}
Currently there's no document about how to use this to passthrough information by frameworks, and we need to document it clearly.
现在没有关于框架如何使用这个库进行信息透传的详细文档,我们应当补充一个。
Reserved the first issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.