pub struct Notification {
pub channel: String,
pub title: String,
pub content: String,
pub level: NotifyLevel,
pub metadata: Value,
}Expand description
通知消息 — 对齐 PHP think\notify\Message
使用 Builder 模式构建通知内容,通过 Notifier::send 发送。
§PHP 对齐
// PHP think\facade\Notify
Notify::channel('slack')
->title('部署完成')
->content('服务已成功部署到生产环境')
->level('info')
->send();§Rust 用法
ⓘ
use sz_rust_state_facade::notify::{Notification, MemoryNotifier, NotifyLevel};
let msg = Notification::new()
.channel("slack")
.title("部署完成")
.content("服务已成功部署到生产环境")
.level(NotifyLevel::Info);
let notifier = MemoryNotifier::new();
notifier.send(msg).unwrap();Fields§
§channel: String通知渠道(如 slack、sms、mail)
title: String通知标题
content: String通知正文
level: NotifyLevel通知级别
metadata: Value附加元数据(JSON 值,供具体 Notifier 使用)
Implementations§
Source§impl Notification
impl Notification
Sourcepub fn new() -> Notification
pub fn new() -> Notification
创建空通知消息
Sourcepub fn channel(self, channel: impl Into<String>) -> Notification
pub fn channel(self, channel: impl Into<String>) -> Notification
设置通知渠道
Sourcepub fn title(self, title: impl Into<String>) -> Notification
pub fn title(self, title: impl Into<String>) -> Notification
设置通知标题
Sourcepub fn content(self, content: impl Into<String>) -> Notification
pub fn content(self, content: impl Into<String>) -> Notification
设置通知正文
Sourcepub fn level(self, level: NotifyLevel) -> Notification
pub fn level(self, level: NotifyLevel) -> Notification
设置通知级别
Sourcepub fn metadata(self, metadata: Value) -> Notification
pub fn metadata(self, metadata: Value) -> Notification
设置附加元数据
Sourcepub fn validate(&self) -> Result<(), NotifyError>
pub fn validate(&self) -> Result<(), NotifyError>
校验必填字段
§返回
- 渠道为空 →
NotifyError::MissingField - 标题为空 →
NotifyError::MissingField - 内容为空 →
NotifyError::MissingField
Trait Implementations§
Source§impl Clone for Notification
impl Clone for Notification
Source§fn clone(&self) -> Notification
fn clone(&self) -> Notification
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 Notification
impl Debug for Notification
Source§impl Default for Notification
impl Default for Notification
Source§fn default() -> Notification
fn default() -> Notification
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for Notification
impl RefUnwindSafe for Notification
impl Send for Notification
impl Sync for Notification
impl Unpin for Notification
impl UnsafeUnpin for Notification
impl UnwindSafe for Notification
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.