Skip to content

Commit

Permalink
Keep input module locked down
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Jun 28, 2023
1 parent ff679d1 commit 322ec2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 10 additions & 3 deletions data/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ pub fn parse(buffer: Buffer, input: &str) -> Result<Input, command::Error> {

#[derive(Debug, Clone)]
pub struct Input {
pub buffer: Buffer,
pub content: Content,
buffer: Buffer,
content: Content,
}

impl Input {
pub fn command(buffer: Buffer, command: Command) -> Self {
Self {
buffer,
content: Content::Command(command),
}
}

pub fn server(&self) -> &Server {
self.buffer.server()
}
Expand Down Expand Up @@ -74,7 +81,7 @@ impl Input {
}

#[derive(Debug, Clone)]
pub enum Content {
enum Content {
Text(String),
Command(Command),
}
Expand Down
9 changes: 5 additions & 4 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ mod nick_list {
match message {
Message::Whois(user) => {
let command = data::Command::Whois(None, user.nickname().to_string());
let input = data::Input {
buffer: data::Buffer::Channel(server.clone(), channel.to_string()),
content: data::input::Content::Command(command),
};

let input = data::Input::command(
data::Buffer::Channel(server.clone(), channel.to_string()),
command,
);

if let Some(encoded) = input.encoded() {
clients.send(server, encoded);
Expand Down

0 comments on commit 322ec2e

Please sign in to comment.