MCPcopy Create free account
hub / github.com/actix/examples / parse_client_command

Function parse_client_command

websockets/chat-tcp/src/client.rs:88–116  ·  view source on GitHub ↗
(msg: &str)

Source from the content-addressed store, hash-verified

86}
87
88fn parse_client_command(msg: &str) -> Option<codec::ChatRequest> {
89 let m = msg.trim();
90
91 if m.is_empty() {
92 return None;
93 }
94
95 // we check for /sss type of messages
96 if m.starts_with('/') {
97 let v: Vec<&str> = m.splitn(2, ' ').collect();
98 match v[0] {
99 "/list" => Some(codec::ChatRequest::List),
100 "/join" => {
101 if v.len() == 2 {
102 Some(codec::ChatRequest::Join(v[1].to_owned()))
103 } else {
104 println!("!!! room name is required");
105 None
106 }
107 }
108 _ => {
109 println!("!!! unknown command");
110 None
111 }
112 }
113 } else {
114 Some(codec::ChatRequest::Message(m.to_owned()))
115 }
116}

Callers

nothing calls this directly

Calls 2

JoinClass · 0.70
MessageClass · 0.70

Tested by

no test coverage detected