add comments
This commit is contained in:
20
src/lib.rs
20
src/lib.rs
@@ -48,6 +48,7 @@ pub struct DingTalk<'a> {
|
||||
/// DingTalk message type
|
||||
/// * TEXT - text message
|
||||
/// * MARKDONW - markdown message
|
||||
/// * LINK - link message
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum DingTalkMessageType {
|
||||
TEXT,
|
||||
@@ -108,6 +109,13 @@ impl <'a> DingTalkMessage<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set markdown
|
||||
pub fn markdown(mut self, markdown_title: &'a str, markdown_content: &'a str) -> Self {
|
||||
self.markdown_title = markdown_title;
|
||||
self.markdown_content = markdown_content;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set link
|
||||
pub fn link(mut self, link_title: &'a str, link_text: &'a str, link_pic_url: &'a str, link_message_url: &'a str) -> Self {
|
||||
self.link_title = link_title;
|
||||
@@ -117,13 +125,6 @@ impl <'a> DingTalkMessage<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set markdown
|
||||
pub fn markdown(mut self, markdown_title: &'a str, markdown_content: &'a str) -> Self {
|
||||
self.markdown_title = markdown_title;
|
||||
self.markdown_content = markdown_content;
|
||||
self
|
||||
}
|
||||
|
||||
/// At all
|
||||
pub fn at_all(mut self) -> Self {
|
||||
self.at_all = true;
|
||||
@@ -198,6 +199,9 @@ impl <'a> DingTalk<'a> {
|
||||
}
|
||||
|
||||
/// Send DingTalk message
|
||||
///
|
||||
/// 1. Create DingTalk JSON message
|
||||
/// 2. POST JSON message to DingTalk server
|
||||
pub fn send_message(&self, dingtalk_message: &DingTalkMessage) -> XResult<()> {
|
||||
let mut message_json = match dingtalk_message.message_type {
|
||||
DingTalkMessageType::TEXT => object!{
|
||||
@@ -285,7 +289,7 @@ impl <'a> DingTalk<'a> {
|
||||
signed_url
|
||||
}
|
||||
|
||||
// SAFE? may cause memory leak?
|
||||
// SAFE? may these codes cause memory leak?
|
||||
fn string_to_a_str(s: &str) -> &'a str {
|
||||
Box::leak(s.to_owned().into_boxed_str())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user