存0的情况
- 数值型但是需要统计:比如余额,订单总额
存null的情况
- 外键可以为空:比如admin_user_id)如果为系统操作,可以为null,这时候存0必须取消数据库约束,或者不建外键约束,都不如存null好
存”的情况
- 非必填且填写的字符串可以为空字符串:比如外国人的middle name,存”可以方便的拼接full name,这个时候如果不需要拼接,你还是可以存null.
- 框架不支持修改时自动将null呈现为”,且保存时自动”改为null
A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm.
struct Counter {
// The counter value
value: i32,
}
#[derive(Debug, Clone, Copy)]
pub enum Message {
IncrementPressed,
DecrementPressed,
}
use iced::widget::{button, column, text, Column};
impl Counter {
pub fn view(&self) -> Column<Message> {
// We use a column: a simple vertical layout
column![
// The increment button. We tell it to produce an
// `IncrementPressed` message when pressed
button("+").on_press(Message::IncrementPressed),
// We show the value of the counter here
text(self.value).size(50),
// The decrement button. We tell it to produce a
// `DecrementPressed` message when pressed
button("-").on_press(Message::DecrementPressed),
]
}
pub fn update(&mut self, message: Message) {
match message {
Message::IncrementPressed => {
self.value += 1;
}
Message::DecrementPressed => {
self.value -= 1;
}
}
}
}
Dioxus 是一个可移植的、高性能的、符合人体工程学的框架,使用 Rust 语言构建跨平台的用户界面。
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
cx.render(rsx! {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
})
}
Dioxus 可用于生成 网页前端、桌面应用、静态网站、移动端应用、TUI程序、等多类平台应用。
如果你能够熟悉使用 React 框架,那 Dioxus 对你来说将非常简单。
Build smaller, faster, and more secure desktop applications with a web frontend.
egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
ui.heading("My egui Application");
ui.horizontal(|ui| {
ui.label("Your name: ");
ui.text_edit_singleline(&mut name);
});
ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
age += 1;
}
ui.label(format!("Hello '{}', age {}", name, age));
A framework for creating reliable and efficient web applications.
use yew::prelude::*;
#[function_component]
fn App() -> Html {
let counter = use_state(|| 0);
let onclick = {
let counter = counter.clone();
move |_| {
let value = *counter + 1;
counter.set(value);
}
};
html! {
<div>
<button {onclick}>{ "+1" }</button>
<p>{ *counter }</p>
</div>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}
We use the following design goals as a guide when developing Slint: