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

Callers

nothing calls this directly

Calls 2

JoinClass · 0.70
MessageClass · 0.70

Tested by

no test coverage detected