写了个闭包作为参数的函数:
pub fn internal_creator_use_twitter_pool<F>(&mut self, pool_id: &PoolId, mut f: F)
where F: FnMut(&mut TwitterPool);
结果编译就报:
error[E0277]: the trait bound `F: near_sdk::serde::Serialize` is not satisfied
--> src/twitter_giveaway.rs:148:1
|
148 | #[near_bindgen]
| ^^^^^^^^^^^^^^^ the trait `near_sdk::serde::Serialize` is not implemented for `F`
|
::: /Users/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.68/src/value/mod.rs:940:8
|
940 | T: Serialize,
| --------- required by this bound in `to_value`
|
= note: required because of the requirements on the impl of `near_sdk::serde::Serialize` for `&F`
= note: this error originates in the macro `json_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `F`
|
160 | pub fn internal_creator_use_twitter_pool<F: near_sdk::serde::Serialize>(&mut self, pool_id: &PoolId,mut f: F)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
改成pub(crate)后,编译通过,但是不懂为什么。
可见度不同
pub(crate)
在当前crate
中可见, 外部crate
不可见pub
在外部crate
可见pub
比pub(crate)
可见度高, 可能有冲突