pub struct BaseException {
pub code: i32,
pub msg: String,
pub message_key: Option<String>,
}Expand description
BaseException — 对齐 PHP app\common\exception\BaseException
PHP 原始实现:
class BaseException extends Exception {
public $code = 0;
public $message = 'invalid parameters';
public function __construct($params = []) {
if (array_key_exists('code', $params)) { $this->code = $params['code']; }
if (array_key_exists('msg', $params)) { $this->message = $params['msg']; }
}
}Fields§
§code: i32错误码(对齐 PHP $code)
msg: String错误消息(对齐 PHP $message,PHP 用 msg 键传入)
message_key: Option<String>本地化消息键(i18n 翻译用,默认 None 表示 msg 已是最终文案)
设置后由上层(如 sz-rust-mvc-facade 的 i18n_error::localize_exception)
通过 i18n 模块翻译为指定语言文案。
Implementations§
Source§impl BaseException
impl BaseException
Sourcepub fn new(code: ErrorCode, msg: impl Into<String>) -> Self
pub fn new(code: ErrorCode, msg: impl Into<String>) -> Self
创建 BaseException(对齐 PHP new BaseException(['code' => x, 'msg' => y]))
Sourcepub fn with_message_key(self, key: impl Into<String>) -> Self
pub fn with_message_key(self, key: impl Into<String>) -> Self
设置本地化消息键(i18n 翻译用)
Sourcepub fn message_key(&self) -> Option<&str>
pub fn message_key(&self) -> Option<&str>
获取本地化消息键(无则 None)
Sourcepub fn not_login(msg: impl Into<String>) -> Self
pub fn not_login(msg: impl Into<String>) -> Self
未登录快捷构造(对齐 PHP throw new BaseException(['code' => -1, 'msg' => 'not_login']))
Sourcepub fn user_not_found(msg: impl Into<String>) -> Self
pub fn user_not_found(msg: impl Into<String>) -> Self
用户不存在快捷构造(对齐 PHP throw new BaseException(['msg' => '没有找到用户信息', 'code' => -2]))
Sourcepub fn user_disabled(msg: impl Into<String>) -> Self
pub fn user_disabled(msg: impl Into<String>) -> Self
用户已禁用快捷构造(对齐 PHP throw new BaseException(['msg' => '您已离职', 'code' => -3]))
Sourcepub fn validate_failed(msg: impl Into<String>) -> Self
pub fn validate_failed(msg: impl Into<String>) -> Self
验证失败快捷构造
Trait Implementations§
Source§impl Clone for BaseException
impl Clone for BaseException
Source§fn clone(&self) -> BaseException
fn clone(&self) -> BaseException
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BaseException
impl Debug for BaseException
Source§impl Default for BaseException
impl Default for BaseException
Source§impl Display for BaseException
impl Display for BaseException
Source§impl Error for BaseException
impl Error for BaseException
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for BaseException
impl RefUnwindSafe for BaseException
impl Send for BaseException
impl Sync for BaseException
impl Unpin for BaseException
impl UnsafeUnpin for BaseException
impl UnwindSafe for BaseException
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more