pub struct GopherMenu<W>where
W: Write,{ /* private fields */ }
Implementations§
Source§impl<'a, W> GopherMenu<&'a W>
impl<'a, W> GopherMenu<&'a W>
Sourcepub fn with_write(target: &'a W) -> Self
pub fn with_write(target: &'a W) -> Self
Examples found in repository?
examples/simple_server.rs (line 16)
9fn handle_client(stream: TcpStream) -> io::Result<()> {
10 let mut line = String::new();
11 BufReader::new(stream.try_clone()?).read_line(&mut line)?;
12 let line = line.trim();
13
14 println!("New request: {}", line);
15
16 let mut menu = GopherMenu::with_write(&stream);
17
18 let menu_link = |text: &str, selector: &str|
19 menu.write_entry(ItemType::Directory, text, selector, HOST, PORT);
20
21 match line {
22 "/" | "" => {
23 menu.info("Hi!")?;
24 menu.info("Welcome to my Gopher server!")?;
25 menu_link("Tomatoes", "/tomato")?;
26 menu.info("Opinion piece about tomatoes")?;
27 menu_link("Potatoes", "/potato")?;
28 menu.info("Opinion piece about potatoes")?;
29 menu_link("Go to unknown link", "/lel")?;
30 }
31 "/tomato" => {
32 menu.info("Tomatoes are not good")?;
33 menu_link("Home page", "/")?;
34 }
35 "/potato" => {
36 menu.info("Potatoes are the best")?;
37 menu_link("Home page", "/")?;
38 }
39 x => {
40 menu.info(&format!("Unknown link: {}", x))?;
41 menu_link("Home page", "/")?;
42 }
43 };
44 menu.end()?;
45 Ok(())
46}
Sourcepub fn info(&self, text: &str) -> Result<()>
pub fn info(&self, text: &str) -> Result<()>
Examples found in repository?
examples/simple_server.rs (line 23)
9fn handle_client(stream: TcpStream) -> io::Result<()> {
10 let mut line = String::new();
11 BufReader::new(stream.try_clone()?).read_line(&mut line)?;
12 let line = line.trim();
13
14 println!("New request: {}", line);
15
16 let mut menu = GopherMenu::with_write(&stream);
17
18 let menu_link = |text: &str, selector: &str|
19 menu.write_entry(ItemType::Directory, text, selector, HOST, PORT);
20
21 match line {
22 "/" | "" => {
23 menu.info("Hi!")?;
24 menu.info("Welcome to my Gopher server!")?;
25 menu_link("Tomatoes", "/tomato")?;
26 menu.info("Opinion piece about tomatoes")?;
27 menu_link("Potatoes", "/potato")?;
28 menu.info("Opinion piece about potatoes")?;
29 menu_link("Go to unknown link", "/lel")?;
30 }
31 "/tomato" => {
32 menu.info("Tomatoes are not good")?;
33 menu_link("Home page", "/")?;
34 }
35 "/potato" => {
36 menu.info("Potatoes are the best")?;
37 menu_link("Home page", "/")?;
38 }
39 x => {
40 menu.info(&format!("Unknown link: {}", x))?;
41 menu_link("Home page", "/")?;
42 }
43 };
44 menu.end()?;
45 Ok(())
46}
Sourcepub fn write_entry(
&self,
item_type: ItemType,
text: &str,
selector: &str,
host: &str,
port: u16,
) -> Result<()>
pub fn write_entry( &self, item_type: ItemType, text: &str, selector: &str, host: &str, port: u16, ) -> Result<()>
Examples found in repository?
examples/simple_server.rs (line 19)
9fn handle_client(stream: TcpStream) -> io::Result<()> {
10 let mut line = String::new();
11 BufReader::new(stream.try_clone()?).read_line(&mut line)?;
12 let line = line.trim();
13
14 println!("New request: {}", line);
15
16 let mut menu = GopherMenu::with_write(&stream);
17
18 let menu_link = |text: &str, selector: &str|
19 menu.write_entry(ItemType::Directory, text, selector, HOST, PORT);
20
21 match line {
22 "/" | "" => {
23 menu.info("Hi!")?;
24 menu.info("Welcome to my Gopher server!")?;
25 menu_link("Tomatoes", "/tomato")?;
26 menu.info("Opinion piece about tomatoes")?;
27 menu_link("Potatoes", "/potato")?;
28 menu.info("Opinion piece about potatoes")?;
29 menu_link("Go to unknown link", "/lel")?;
30 }
31 "/tomato" => {
32 menu.info("Tomatoes are not good")?;
33 menu_link("Home page", "/")?;
34 }
35 "/potato" => {
36 menu.info("Potatoes are the best")?;
37 menu_link("Home page", "/")?;
38 }
39 x => {
40 menu.info(&format!("Unknown link: {}", x))?;
41 menu_link("Home page", "/")?;
42 }
43 };
44 menu.end()?;
45 Ok(())
46}
Sourcepub fn end(&mut self) -> Result<()>
pub fn end(&mut self) -> Result<()>
Examples found in repository?
examples/simple_server.rs (line 44)
9fn handle_client(stream: TcpStream) -> io::Result<()> {
10 let mut line = String::new();
11 BufReader::new(stream.try_clone()?).read_line(&mut line)?;
12 let line = line.trim();
13
14 println!("New request: {}", line);
15
16 let mut menu = GopherMenu::with_write(&stream);
17
18 let menu_link = |text: &str, selector: &str|
19 menu.write_entry(ItemType::Directory, text, selector, HOST, PORT);
20
21 match line {
22 "/" | "" => {
23 menu.info("Hi!")?;
24 menu.info("Welcome to my Gopher server!")?;
25 menu_link("Tomatoes", "/tomato")?;
26 menu.info("Opinion piece about tomatoes")?;
27 menu_link("Potatoes", "/potato")?;
28 menu.info("Opinion piece about potatoes")?;
29 menu_link("Go to unknown link", "/lel")?;
30 }
31 "/tomato" => {
32 menu.info("Tomatoes are not good")?;
33 menu_link("Home page", "/")?;
34 }
35 "/potato" => {
36 menu.info("Potatoes are the best")?;
37 menu_link("Home page", "/")?;
38 }
39 x => {
40 menu.info(&format!("Unknown link: {}", x))?;
41 menu_link("Home page", "/")?;
42 }
43 };
44 menu.end()?;
45 Ok(())
46}
Auto Trait Implementations§
impl<W> Freeze for GopherMenu<W>where
W: Freeze,
impl<W> RefUnwindSafe for GopherMenu<W>where
W: RefUnwindSafe,
impl<W> Send for GopherMenu<W>where
W: Send,
impl<W> Sync for GopherMenu<W>where
W: Sync,
impl<W> Unpin for GopherMenu<W>where
W: Unpin,
impl<W> UnwindSafe for GopherMenu<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more