6个版本
0.2.0 | 2019年6月10日 |
---|---|
0.1.4 | 2019年6月8日 |
#745 in 过程宏
11KB
166 代码行数(不包括注释)
rcstruct
rcstruct 无示例
查看完整示例,请参阅 examples/01a.rs
struct GUIInternal {
running: bool,
event_recv: Receiver<Event>,
action_send: Sender<Action>,
}
impl GUIInternal {
fn send_action(&self, action: Action) -> Rt {
Ok(self.action_send.send(action)?)
}
fn running(&self) -> Rt<bool> {
Ok(self.running)
}
fn quit(&mut self) -> Rt {
self.running = false;
Ok(())
}
fn events(&self) -> Rt<impl IntoIterator<Item = Event>> {
let events = Vec::new();
Ok(events)
}
}
pub struct GUI(Rc<RefCell<GUIInternal>>);
impl GUI {
pub fn new(event_recv: Receiver<Event>, action_send: Sender<Action>) -> Rt<Self> {
let running = true;
Ok(GUI(Rc::new(RefCell::new(GUIInternal { running, event_recv, action_send, }))))
}
pub fn send_action(&self, action: Action) -> Rt {
self.0.borrow().send_action(action)
}
pub fn running(&self) -> Rt<bool> {
self.0.borrow().running()
}
pub fn quit(&self) -> Rt {
self.0.borrow_mut().quit()
}
pub fn events(&self) -> Rt<impl IntoIterator<Item = Event>> {
self.0.borrow().events()
}
}
rcstruct 有示例
查看完整示例,请参阅 examples/01b.rs
rcstruct::rcstruct! {
pub struct GUI {
running: bool,
event_recv: Receiver<Event>,
action_send: Sender<Action>,
}
impl {
pub new(event_recv: Receiver<Event>, action_send: Sender<Action>) -> Rt<Self> {
let running = true;
{ running, event_recv, action_send, }
}
pub fn send_action(&self, action: Action) -> Rt {
Ok(self.action_send.send(action)?)
}
pub fn running(&self) -> Rt<bool> {
Ok(self.running)
}
pub fn quit(&mut self) -> Rt {
self.running = false;
Ok(())
}
pub fn events(&self) -> Rt<impl IntoIterator<Item = Event>> {
let events = Vec::new();
Ok(events)
}
}
}
许可证
许可证为以下之一
-
Apache许可证,版本2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
-
MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确表示,否则您提交的任何有意包含在此crate中的贡献,根据Apache-2.0许可证定义,应按照上述方式双重许可,不附加任何额外条款或条件。
依赖项
约2MB
约46K 代码行数(约额外行数)