rust: 枚举
//!# encoding: utf-8 //!# 版权所有 2026 ©涂聚文有限公司™ ® //!# 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 //!# 描述Design Patterns //!# Author : geovindu,Geovin Du 涂聚文. //!# IDE : RustRover 2025.1.1 Rust rustc 1.98.1 //!# os : windows 10 //!# database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j //!# Datetime : 2026/9/25 20:54 //!# User : geovindu //!# Product : RustRover //!# Project : RustDesignPatterns //!# File : check_patterns.rs // encoding: utf-8 // 版权所有 2026 ©涂聚文有限公司™ ® // Author : geovindu,Geovin Du 涂聚文. // 设计模式枚举调度各bll demo对标Python CheckPatterns.py use crate::bll; use crate::lang::{PATTERN_ENUM_MAP,current_lang_code}; use tokio; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum DesignPattern { Memento, Command, State, TemplateMethod, Visitor, Strategy, Observe, Mediator, Iterator, ChainofResponsibility, Proxy, Flyweight, Facade, Decorator, Composite, Singleton, Prototype, Bridge, Adapter, Builder, AbstractFactory, Factory, SimpleFactory, FactoryMethod, NullObject, Interpreter, Registry, Borg, LazyEvaluation, Pool, ConditionVariable, Mutex, Monitor, ReadWriteLock, Semaphore, NBarrier, BoundedParallelism, Broadcast, Coroutines, Generators, Reactor, Parallelism, ProducerConsumer, FanIn, FanOut, Pipeline, WorkerPool, FuturesPromises, PublishSubscribe, PushPull, Bulkheads, CircuitBreaker, Deadline, FailFast, Handshaking, SteadyState, TimingFunctions, FunctionalOptions, CascadingFailures, ThreadPool, Watchdog, Barrier, Future, MessageQueue, RateLimiter, Retry, AntiGodObject, AntiSpaghetti, AntiLavaFlow, } impl DesignPattern { /// 枚举名称转中文对标Python _name_to_cn pub fn name_to_cn(self)-String{ let name format!({:?},self); let map PATTERN_ENUM_MAP.get().unwrap(); if let Some(arr) map.get(name.as_str()){ let idx match current_lang_code(){ 10, 21, _2, }; arr[idx].to_string() }else{ name } } /// 执行demo示例对标 show_example() pub fn show_example(self){ println!(\n 展示【{} Pattern{}】示例 ,format!({:?},self),self.name_to_cn()); match self { DesignPattern::Memento bll::memento_bll::MementoBll::demo(), DesignPattern::Command bll::command_bll::CommandBll::demo(), DesignPattern::State bll::state_bll::StateBll::demo(), DesignPattern::TemplateMethod bll::templatemethod_bll::TemplateMethodBll::demo(), DesignPattern::Visitor bll::visitor_bll::VisitorBll::demo(), DesignPattern::Strategy bll::strategy_bll::StrategyBll::demo(), DesignPattern::Observe bll::observe_bll::ObserveBll::demo(), DesignPattern::Mediator bll::mediator_bll::MediatorBll::demo(), DesignPattern::Iterator bll::iterator_bll::IteratorBll::demo(), DesignPattern::ChainofResponsibility bll::chainofresponsibility_bll::ChainofResponsibilityBll::dudemo(), DesignPattern::Proxy bll::proxy_bll::ProxyBll::demo(), DesignPattern::Flyweight bll::flyweight_bll::FlyweightBll::demo(), DesignPattern::Facade bll::facade_bll::FacadeBll::demo(), DesignPattern::Decorator bll::decorator_bll::DecoratorBll::demo(), DesignPattern::Composite bll::composite_bll::CompositeBll::demo(), DesignPattern::Singleton bll::singleton_bll::SingletonBll::demo(), DesignPattern::Prototype bll::prototype_bll::PrototypeBll::demo(), DesignPattern::Bridge bll::bridge_bll::BridgeBll::demo(), DesignPattern::Adapter bll::adapter_bll::AdapterBll::demo(), DesignPattern::Builder bll::builder_bll::BuilderBll::demo(), DesignPattern::AbstractFactory bll::abstractfactory_bll::AbstractFactoryBll::demo(), DesignPattern::Factory bll::factory_bll::FactoryBll::demo(), DesignPattern::SimpleFactory bll::simplefactory_bll::SimpleFactoryBll::demo(), DesignPattern::FactoryMethod bll::factorymethod_bll::FactoryMethodBll::demo(), DesignPattern::NullObject bll::nullobject_bll::NullObjectBll::demo(), DesignPattern::Interpreter bll::interpreter_bll::InterpreterBll::demo(), DesignPattern::Registry bll::registry_bll::RegistryBll::demo(), DesignPattern::ConditionVariable bll::conditionvariable_bll::ConditionVariableBll::demo(), DesignPattern::Mutex bll::mutex_bll::MutexBll::demo(), DesignPattern::Monitor bll::monitor_bll::MonitorBll::demo(), DesignPattern::ReadWriteLock bll::readwritelock_bll::ReadWriteLockBll::demo(), DesignPattern::Semaphore bll::semaphore_bll::SemaphoreBll::demo(), DesignPattern::NBarrier bll::nbarrier_bll::NBarrierBll::demo(), DesignPattern::BoundedParallelism bll::boundedparallelism_bll::BoundedParallelismBll::demo(), DesignPattern::Broadcast bll::broadcast_bll::BroadcastBll::demo(), DesignPattern::Coroutines { // 异步demotokio运行对标asyncio.run let rt tokio::runtime::Runtime::new().unwrap(); rt.block_on(bll::coroutines_bll::CoroutinesBll::demo()); } DesignPattern::Generators bll::generators_bll::GeneratorsBll::demo(), DesignPattern::Reactor bll::reactor_bll::ReactorBll::demo(), DesignPattern::Parallelism bll::parallelism_bll::ParallelismBll::demo(), DesignPattern::ProducerConsumer bll::producerconsumer_bll::ProducerConsumerBll::demo(), DesignPattern::FanIn bll::fanin_bll::FanInBll::demo(), DesignPattern::FanOut bll::fanout_bll::FanOutBll::demo(), DesignPattern::Pipeline bll::pipeline_bll::PipelineBll::demo(), DesignPattern::WorkerPool bll::workerpool_bll::WorkerPoolBll::demo(), DesignPattern::FuturesPromises bll::futurespromises_bll::FuturesPromisesBll::demo(), DesignPattern::PublishSubscribe bll::publishsubscribe_bll::PublishSubscribeBll::demo(), DesignPattern::PushPull bll::pushpull_bll::PushPullBll::demo(), DesignPattern::Bulkheads bll::bulkheads_bll::BulkheadsBll::demo(), DesignPattern::CircuitBreaker bll::circuitbreaker_bll::CircuitBreakerBll::demo(), DesignPattern::Deadline bll::deadline_bll::DeadlineBll::demo(), DesignPattern::FailFast bll::failfast_bll::FailFastBll::demo(), DesignPattern::Handshaking bll::handshaking_bll::HandshakingBll::demo(), DesignPattern::SteadyState bll::steadystate_bll::SteadyStateBll::demo(), DesignPattern::TimingFunctions bll::timingfunctions_bll::TimingFunctionsBll::demo(), DesignPattern::FunctionalOptions bll::functionaloptions_bll::FunctionalOptionsBll::demo(), DesignPattern::CascadingFailures bll::cascadingfailures_bll::CascadingFailuresBll::demo(), DesignPattern::ThreadPool bll::threadpool_bll::ThreadPoolBll::demo(), DesignPattern::Watchdog bll::watchdog_bll::WatchdogBll::demo(), DesignPattern::Barrier bll::barrier_bll::BarrierBll::demo(), DesignPattern::Future bll::future_bll::FutureBll::demo(), DesignPattern::MessageQueue bll::messagequeue_bll::MessageQueueBll::demo(), DesignPattern::RateLimiter bll::ratelimiter_bll::RateLimiterBll::demo(), DesignPattern::Retry bll::retry_bll::RetryBll::demo(), DesignPattern::AntiGodObject bll::antigodobject_bll::AntiGodObjectBll::demo(), DesignPattern::AntiSpaghetti bll::antispaghetti_bll::AntiSpaghettiBll::demo(), DesignPattern::AntiLavaFlow bll::antilavaflow_bll::AntiLavaFlowBll::demo(), DesignPattern::Borg unimplemented!(Borg模式待实现), DesignPattern::LazyEvaluation unimplemented!(LazyEvaluation模式待实现), DesignPattern::Pool unimplemented!(对象池简写模式待实现), } } /// 把枚举转为迭代列表用于菜单遍历 pub fn all() - static [DesignPattern] { [ DesignPattern::Memento, DesignPattern::Command, DesignPattern::State, DesignPattern::TemplateMethod, DesignPattern::Visitor, DesignPattern::Strategy, DesignPattern::Observe, DesignPattern::Mediator, DesignPattern::Iterator, DesignPattern::ChainofResponsibility, DesignPattern::Proxy, DesignPattern::Flyweight, DesignPattern::Facade, DesignPattern::Decorator, DesignPattern::Composite, DesignPattern::Singleton, DesignPattern::Prototype, DesignPattern::Bridge, DesignPattern::Adapter, DesignPattern::Builder, DesignPattern::AbstractFactory, DesignPattern::Factory, DesignPattern::SimpleFactory, DesignPattern::FactoryMethod, DesignPattern::NullObject, DesignPattern::Interpreter, DesignPattern::Registry, DesignPattern::Borg, DesignPattern::LazyEvaluation, DesignPattern::Pool, DesignPattern::ConditionVariable, DesignPattern::Mutex, DesignPattern::Monitor, DesignPattern::ReadWriteLock, DesignPattern::Semaphore, DesignPattern::NBarrier, DesignPattern::BoundedParallelism, DesignPattern::Broadcast, DesignPattern::Coroutines, DesignPattern::Generators, DesignPattern::Reactor, DesignPattern::Parallelism, DesignPattern::ProducerConsumer, DesignPattern::FanIn, DesignPattern::FanOut, DesignPattern::Pipeline, DesignPattern::WorkerPool, DesignPattern::FuturesPromises, DesignPattern::PublishSubscribe, DesignPattern::PushPull, DesignPattern::Bulkheads, DesignPattern::CircuitBreaker, DesignPattern::Deadline, DesignPattern::FailFast, DesignPattern::Handshaking, DesignPattern::SteadyState, DesignPattern::TimingFunctions, DesignPattern::FunctionalOptions, DesignPattern::CascadingFailures, DesignPattern::ThreadPool, DesignPattern::Watchdog, DesignPattern::Barrier, DesignPattern::Future, DesignPattern::MessageQueue, DesignPattern::RateLimiter, DesignPattern::Retry, DesignPattern::AntiGodObject, DesignPattern::AntiSpaghetti, DesignPattern::AntiLavaFlow, ] } }//!# encoding: utf-8 //!# 版权所有 2026 ©涂聚文有限公司™ ® //!# 许可信息查看言語成了邀功盡責的功臣還需要行爲每日來值班嗎 //!# 描述Design Patterns //!# Author : geovindu,Geovin Du 涂聚文. //!# IDE : RustRover 2025.1.1 Rust rustc 1.98.1 //!# os : windows 10 //!# database : mysql 9.0 sql server 2019, postgreSQL 17.0 Oracle 21c Neo4j //!# Datetime : 2026/9/25 20:52 //!# User : geovindu //!# Product : RustRover //!# Project : RustDesignPatterns //!# File : main.rs // encoding: utf-8 // 版权所有 2026 ©涂聚文有限公司™ ® // Author : geovindu,Geovin Du 涂聚文. // IDE : VS Code / RustRover // os : windows 10 // Project : pydesignpattern-rs use std::io; use controller::DesignPattern; use crate::lang::{init_lang_map,set_language}; mod controller; mod lang; mod bll; /// 返回 (序列号, OptionDesignPattern)0退出 fn select_design_pattern()-(usize,OptionDesignPattern){ println!({},lang::TITLE_MENU); println!({} 0/{} {},lang::PROMPT_INPUT_NUM,lang::KEY_QUIT,lang::TITLE_EXIT_OPT); let pattern_list DesignPattern::all(); for (idx,pat) in pattern_list.iter().enumerate(){ let display_name pat.name_to_cn(); println!({}. {}{:?},idx1,display_name,pat); } println!(0. {},lang::TITLE_EXIT_OPT); loop{ println!(\n{},lang::PROMPT_INPUT_NUM); let mut buf String::new(); io::stdin().read_line(mut buf).unwrap(); let input buf.trim(); if input 0 || input.eq_ignore_ascii_case(q){ println!( {},lang::MSG_EXIT_PROGRAM); return (0,None); } let Ok(choice) input.parse::usize() else { println!({},lang::MSG_INVALID_INPUT); continue; }; let max pattern_list.len(); if choice 1 choice max{ let selected pattern_list[choice-1]; let cn_name selected.name_to_cn(); println!({}{}对应{},lang::MSG_SELECTED_ITEM,choice,cn_name); return (choice,Some(selected)); }else{ println!({} 1-{},lang::MSG_INVALID_INPUT,max); } } } /// 是否继续选择 fn ask_continue()-bool{ loop{ println!({},lang::PROMPT_CONTINUE_ASK); let mut buf String::new(); io::stdin().read_line(mut buf).unwrap(); let input buf.trim().to_lowercase(); if input lang::KEY_YES{ return true; }else if input lang::KEY_NO{ println!( {},lang::MSG_EXIT_PROGRAM); return false; }else{ println!({} {}/{},lang::MSG_INVALID_INPUT,lang::KEY_YES,lang::KEY_NO); } } } fn main() { // 初始化语言映射 init_lang_map(); // 默认简体中文 set_language(1); println!({},lang::PROMPT_CHOOSE_LANG); let mut buf String::new(); io::stdin().read_line(mut buf).unwrap(); let code buf.trim().parse::u8().unwrap_or(1); set_language(code); println!({},lang::TITLE_MAIN); loop{ let (selected_num, selected_pattern) select_design_pattern(); if selected_num 0{ println!( {},lang::MSG_EXIT_PROGRAM); break; } let pat selected_pattern.unwrap(); let en_name format!({:?},pat); let cn_name pat.name_to_cn(); println!({},lang::MSG_SHOW_PATTERN_HEAD.replace({},{}).replace({},en_name).replace({},cn_name)); pat.show_example(); println!(\n 本次选择的序列号是{},selected_num); if !ask_continue(){ break; } } println!(hi,welcome geovindu.); }

相关新闻

数据库课程设计实战:B+树、查询优化器与2PL并发控制

数据库课程设计实战:B+树、查询优化器与2PL并发控制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/28 12:45:58 阅读更多 →
红外技术三条线:从测温、遥控到AI检测一次捋清

红外技术三条线:从测温、遥控到AI检测一次捋清

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/28 16:38:36 阅读更多 →
2026芯片IP选型指南:从CPU/NPU到接口IP的避坑与实战

2026芯片IP选型指南:从CPU/NPU到接口IP的避坑与实战

1. 芯片IP选型这件事,为什么越来越像一场信息战如果你在2026年还在用“查手册、翻官网、问FAE”这套老办法做芯片IP选型,大概率会踩坑。不是因为你不够专业,而是因为芯片IP这个市场在过去三年发生了结构性变化:品类爆炸、供应商分…

2026/9/30 20:21:36 阅读更多 →

最新新闻

GD32F103入门实践:环境配置、工程模板搭建与烧写全流程解析

GD32F103入门实践:环境配置、工程模板搭建与烧写全流程解析

GD32F103入门实践(一)配置环境,搭建工程模板,烧写程序 先说说我为什么写这个系列。这几年国产MCU用得多,GD32F103是绕不开的一颗料。它和STM32F103的引脚、寄存器级兼容,价格又低一截,很多产品…

2026/10/5 14:36:12 阅读更多 →
VMware Workstation Pro 16安装Ubuntu 20.04虚拟机完整指南

VMware Workstation Pro 16安装Ubuntu 20.04虚拟机完整指南

我这些年装 Ubuntu 虚拟机,装到闭着眼睛都能把新建虚拟机的向导点完。每次有新人问“我在 Windows 上想跑 Linux,到底用哪个方案”,我给的建议基本没变过——VMware Workstation Pro 16 搭配 Ubuntu 20.04 LTS。这套组合不算新潮,…

2026/10/5 14:36:12 阅读更多 →
中小企业网络设计课程设计全攻略:VLAN划分到仿真验证一步到位

中小企业网络设计课程设计全攻略:VLAN划分到仿真验证一步到位

简介:这是一份计算机网络课程设计报告文档,主题为中小企业网络设计,面向高校计算机相关专业学生及需要撰写同类课程设计报告的读者。文档以小组形式完成,围绕新盟科技公司等百人以下企业的实际建网场景,从需求分析、可…

2026/10/5 14:36:12 阅读更多 →
C++可视化窗口从零实战:从Win32到消息循环与框架迁移

C++可视化窗口从零实战:从Win32到消息循环与框架迁移

1. 写可视化窗口之前,先想清楚这几件事先直接说结论:用C写可视化窗口,很多人第一反应是“去网上找个图形库”,然后一头扎进Qt、wxWidgets、SFML的海洋里,折腾半天连窗口都没弹出来,反而被编译错误劝退。我见…

2026/10/5 14:36:12 阅读更多 →
如何挑选品质可靠的水泥雕塑品牌?专家揭秘选择技巧

如何挑选品质可靠的水泥雕塑品牌?专家揭秘选择技巧

如何挑选品质可靠的水泥雕塑品牌?专家揭秘选择技巧在城市公共艺术和景观设计中,水泥雕塑扮演着至关重要的角色。它们不仅能够提升环境的艺术氛围,还能成为城市的标志性符号。然而,市场上水泥雕塑品牌众多,如何挑选一个…

2026/10/5 14:36:12 阅读更多 →
YOLOv5源码深度解析:用Debug逐行追踪特征图变化

YOLOv5源码深度解析:用Debug逐行追踪特征图变化

写代码的人应该都有过这种经历:模型能跑通,精度也还算行,但你要是突然问一句“这中间特征图到底是怎么变的?”,自己心里立刻就没底了。我接触yolov5源码这件事拖了很久,原因很简单——平时调用detect.py和t…

2026/10/5 14:35:12 阅读更多 →

日新闻

马斯克杀回智能体战场,Grok 4.5万亿参数撑腰,Cursor接手数字白领项目:用TaoToken统一Key跑通多模型Agent工作流

马斯克杀回智能体战场,Grok 4.5万亿参数撑腰,Cursor接手数字白领项目:用TaoToken统一Key跑通多模型Agent工作流

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/5 0:00:22 阅读更多 →
AI编程工具插件机制详解:plugin.json配置与加载失败排查指南

AI编程工具插件机制详解:plugin.json配置与加载失败排查指南

1. 从“plugins”这个词说起:它到底在解决什么问题如果你最近在折腾 AI 编程工具,尤其是 Cursor、Codex CLI、Claude Code 这类带 CLI 的编辑器或命令行助手,那你大概率绕不开一个词——plugins。这个词本身不新鲜,从浏览器到 IDE…

2026/10/5 0:00:23 阅读更多 →
第26课:OpenClaw|日志审计与问题诊断:把日志链路改到 TaoToken 的排查清单

第26课:OpenClaw|日志审计与问题诊断:把日志链路改到 TaoToken 的排查清单

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/5 0:00:23 阅读更多 →

周新闻

KT148A语音芯片外挂8002D功放的工程实践指南

KT148A语音芯片外挂8002D功放的工程实践指南

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/5 5:06:42 阅读更多 →
LLC谐振变换器增益公式推导:从FHA等效到完整归一化表达式

LLC谐振变换器增益公式推导:从FHA等效到完整归一化表达式

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/5 1:10:22 阅读更多 →
ARM架构深度解析:从RISC设计理念到交叉编译实战

ARM架构深度解析:从RISC设计理念到交叉编译实战

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/5 3:06:17 阅读更多 →

月新闻

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/4 11:40:45 阅读更多 →
Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/4 9:43:54 阅读更多 →
黑夜航拍船只数据集训练YOLOV5模型全流程解析

黑夜航拍船只数据集训练YOLOV5模型全流程解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/4 20:14:29 阅读更多 →