Skip to main content

wechat_minapp/new_type/
mod.rs

1//! 用于传参验证
2//!
3mod non_query_page_path;
4mod page_path;
5mod scene;
6
7use crate::error::Error;
8pub use non_query_page_path::NonQueryPagePath;
9pub use page_path::PagePath;
10pub use scene::{SceneString, ValidationSceneError};
11use std::fmt;
12
13/// 页面路径验证错误类型
14#[derive(Debug, Clone, PartialEq)]
15pub enum PagePathError {
16    /// 路径以斜杠开头
17    StartsWithSlash,
18    /// 路径包含参数(应该放在scene字段)
19    ContainsParams,
20    /// 路径格式不正确
21    InvalidFormat,
22    /// 页面路径最大长度 1024 个字符
23    InvalidLength,
24    /// 页面路径包含系统保留参数 'scancode_time'
25    ReservedParameter,
26    /// 页面路径不能为空
27    Empty,
28}
29
30impl std::error::Error for PagePathError {}
31
32impl From<url::ParseError> for PagePathError {
33    fn from(_value: url::ParseError) -> Self {
34        PagePathError::InvalidFormat
35    }
36}
37
38impl From<Error> for PagePathError {
39    fn from(_value: Error) -> Self {
40        PagePathError::InvalidFormat
41    }
42}
43impl fmt::Display for PagePathError {
44    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45        match self {
46            PagePathError::StartsWithSlash => write!(f, "页面路径不能以斜杠开头"),
47            PagePathError::ContainsParams => {
48                write!(f, "页面路径不能携带参数,参数请放在scene字段里")
49            }
50            PagePathError::InvalidFormat => write!(f, "页面路径格式不正确"),
51            PagePathError::InvalidLength => write!(f, "页面路径最大长度 1024 个字符"),
52            PagePathError::Empty => write!(f, "页面路径不能为空"),
53            PagePathError::ReservedParameter => {
54                write!(f, "页面路径包含系统保留参数 'scancode_time'")
55            }
56        }
57    }
58}